【发布时间】:2021-01-19 03:55:37
【问题描述】:
我只是想知道有没有办法让这个脚本 (https://www.cirriustech.co.uk/blog/how-to-auto-tidy-files-in-google-drive/) 在我的驱动器中的特定文件夹上运行。
我有一个使用谷歌表单和表格制作的项目,在谷歌表单中有一个上传表单,文件保存到特定文件夹。我的主文件夹(项目)有子文件夹,其中一个是文件存储的位置。我需要一个脚本,它会在一段时间内删除此文件夹中的文件。
我试图找到任何可以以这种方式工作的脚本,我觉得上面的链接越来越接近我的需要。任何有用的帮助或不同的脚本都会对我有很大帮助。
添加:这是代码
function GetFilesByDate() {
var arrFileIDs = [];
var Threshold = new Date().getTime()-3600*1000*24*7;
// 30 is the number of days
//(3600 seconds = 1 hour, 1000 milliseconds = 1 second, 24 hours = 1 day and 30 days is the duration you wanted
//needed in yr-month-day format
var CullDate = new Date(Threshold);
var strCullDate = Utilities.formatDate(CullDate, "GMT", "yyyy-MM-dd");
console.info(strCullDate);
var FileID = "";
var FileName = "";
//Create an array of file ID's by date criteria
var files = DriveApp.searchFiles(
'modifiedDate < "' + strCullDate + '"');
while (files.hasNext()) {
var file = files.next();
var FileID = file.getId();
var FileName = file.getName();
if (FileName.indexOf('.mp4') > -1 ) {
arrFileIDs.push(FileID);
console.info('FileID: ' + FileID);
console.info('Last Updated: ' + file.getLastUpdated());
console.info('Filename: ' + FileName);
}
}
return arrFileIDs;
console.info('FileIDs Array: ' + arrFileIDs);
};
function DeleteFilesByDate() {
var arrayIDs = GetFilesByDate();
for (var i=0; i < arrayIDs.length; i++) {
console.info('arrayIDs[i]: ' + arrayIDs[i]);
//This deletes a file without needing to move it to the trash
var DelResponse = Drive.Files.remove(arrayIDs[i]);
}
};
我想要完成的是这个。我有来自谷歌表单上传的文件,我希望根据上传日期(上传后 7 / 8 天等)删除这些文件
【问题讨论】:
-
您能添加您正在处理的代码吗?不要仅仅依赖外部链接,所有相关信息都应该在问题中。另外,说明你想要完成什么,你面临什么具体问题,你尝试了什么等等。看看stackoverflow.com/help/how-to-ask
-
我已经添加了它们,TIA。
-
所以,如果我理解正确的话,每次提交 Google 表单时,一些文件都会上传到某个云端硬盘文件夹,并且您希望在特定时间后以编程方式删除这些文件(7天,例如)。这是正确的吗?
-
是的,先生,正确
标签: javascript google-apps-script google-drive-api