Google Apps脚本删除谷歌硬盘中的所有文件?

And*_*coa 10 google-apps-script google-drive-api

我需要删除我的驱动器中的所有文件,超过16 GB,我需要手动删除数小时.

寻求帮助以支持谷歌并没有任何帮助.

我可以移动我执行的Google Apps脚本吗?

pat*_*tt0 9

我将假设您熟悉Google Apps脚本,以便您知道如何在驱动器中创建脚本,管理编辑器等...如果您不是,请从此处开始https://developers.google.com/apps-script/overview.

这里有一个小脚本,它会列出你的所有文件并将它们设置为垃圾桶,你仍然需要去垃圾桶并永久删除.

使用本文时要小心:将所有文件移动到逻辑中

运行它时,您需要取消注释file.setTrashed(true)

function processAllFiles() {
  // we look for the continuation token from the UserProperties
  // this is useful as the script may take more that 5 minutes 
  // (exceed execution time)
  var continuationToken = UserProperties.getProperty('DELETE_ALL_FILES_CONTINUATION_TOKEN');

  if (continuationToken == null) {
    // firt time execution, get all files from drive
    var files = DriveApp.getFiles();
    // get the token and store it in a user property
    var continuationToken = files.getContinuationToken();
    UserProperties.setProperty('DELETE_ALL_FILES_CONTINUATION_TOKEN', continuationToken);
  } else {
    // we continue to execute (and move everything to trash)
    var files = DriveApp.continueFileIterator(continuationToken);
  }

   while (files.hasNext()) {
     var file = files.next();
//     file.setTrashed(true);
     Logger.log(file.getName());
  }

  // finish processing delete the token
  UserProperties.deleteProperty('DELETE_ALL_FILES_CONTINUATION_TOKEN');
}
Run Code Online (Sandbox Code Playgroud)

您可能会留下很多文件夹(如果它们是出于某种原因以编程方式创建的;))因此您可以运行这个小脚本将它们移动到垃圾箱中.不要忘记取消注释下面的行.

function processAllFolder() {
// Log the name of every folder in the user's Drive.
  var folders = DriveApp.getFolders();
  while (folders.hasNext()) {
    var folder = folders.next();
     Logger.log(folder.getName());
     // folder.setTrashed(true);
  }
};
Run Code Online (Sandbox Code Playgroud)

让我知道这对你有什么影响.