admin管理员组

文章数量:1587931

1.Google APP Script
进入APP Scrip,新建项目,重命名。

2.Drive API
添加“服务”,选择“Drive API”并添加

3.Funciton
将以下代码粘贴至“代码.gs”文件中,点击“运行”即可

function myFunction() {
	var files = DriveApp.getTrashedFiles()
 	var count = 0
  	while (files.hasNext()) {
    try {
     	var currentFile = files.next()
      	if (currentFile.isTrashed()) {
          // Drive.Files.remove(currentFile.getId())
          Drive.Files.remove(currentFile.getId(),{supportsTeamDrives:true})
          count++
          // Logger.log('Deleted file ' + count + " : " + currentFile.getName())
      	}
    }
    catch(error) {
      console.log(error.message);
      continue;
    }
  }
  console.log('Total Deletes Files : ' + count);  
}

注意:

  • 删除从“我的云端硬盘”移至回收站的内容
Drive.Files.remove(currentFile.getId())
  • 删除从团队盘移至回收站的内容
Drive.Files.remove(currentFile.getId(),{supportsTeamDrives:true})
  • Google APP Script有运行时间限制,应该是10分钟。如果没删除完,需要多运行几次。

总结
有些小问题,我要删除的都是图片,在删除团队盘移到回收站的内容时,删除300张左右就运行完一次,要重新运行,还不清楚问题出在哪里。

本文标签: 回收站清空文件Googledriver