正如我在评论中所说,你提到的脚本与你想要的相差不远......但我承认你的情况有点复杂所以让我们说这将是政治的另一个例外;-)
也就是说,我没有彻底测试这段代码,所以它可能需要一些调整。我在整个脚本中留下了一些注释日志来测试中间结果,不要犹豫使用它们。另外,考虑更新邮件地址,不要忘记setTrashed
可以手动反转;-)(在尝试新代码时更好)
编辑:我今天早上花了一些时间来测试脚本,它有几个“近似值”;-) 这是一个运行良好的“干净”版本
function DeleteMyOldAvi() {
var pageSize = 200;
var files = null;
var token = null;
var i = null;
var totalFiles = []
var toDelete = []
Logger.clear()
do {
var result = DocsList.getAllFilesForPaging(pageSize, token);
var files = result.getFiles()
var token = result.getToken();
for(n=0;n<files.length;++n){
if(files[n].getName().toLowerCase().match('.avi')=='.avi'){
totalFiles.push([files[n].getName(),files[n].getDateCreated().getTime(),files[n].getId()]);// store name, Date created in mSec, ID in a subarray
// Logger.log(files[n].getName()+' created on '+Utilities.formatDate(files[n].getDateCreated(), 'GMT','MMM-dd-yyyy'))
}
}
} while (files.length == pageSize);// continue until job is done
totalFiles.sort(function(x,y){ // sort array on milliseconds date created (numeric/descending)
var xp = x[1];
var yp = y[1];
return yp-xp ;
});
// Logger.log(totalFiles.length)
if(totalFiles.length>100){
for(nn=totalFiles.length-1;nn>=100;nn--){
toDelete.push(totalFiles[nn]) ;// store the files to delete
}
// Logger.log(toDelete)
for(n=0;n<toDelete.length;++n){
var file = toDelete[n]
DocsList.getFileById(file[2]).setTrashed(true);// move to trash each file that is in the toDelete array
Logger.log(file[0]+' was deleted');// log the file name to create mail message
}
MailApp.sendEmail('myMail@gmail.com', 'Script AUTODELETE report', Logger.getLog());// send yourself a mail
}else{
MailApp.sendEmail('myMail@gmail.com', 'Script AUTODELETE report', 'No file deleted');// send yourself a mail
}
}