所以我通过复制和粘贴其他人的东西创建了我的第一个脚本。在某个地方,看起来我删除了允许触发器(时间和放大)工作的东西。
我尝试从其他类似问题中提出一些建议,但没有结果......
function DolistFilesInFolder() {
listFilesInFolder("specified folder"); //Enter folder name in between " "
}
function listFilesInFolder(folderName) {
Logger.log(folderName);
var folders = DriveApp.getFoldersByName(folderName);
var folder = folders.next();
var contentfolders = folder.getFolders(); //fetches the folders inside the folder
var contentfiles = folder.getFiles(); //fetches the files inside the folder
// Find or add sheet with folder name
var ss = SpreadsheetApp.getActive();
var sheet = ss.getSheetByName(folderName);
if (sheet) {
Logger.log("found");
}
else {
sheet = ss.insertSheet(folderName);
}
sheet.clear();
sheet.appendRow(["Name", "Date", "URL"]);
// Loop over folders in folder, using file iterator
while (contentfolders.hasNext()) {
var file = contentfolders.next();
var data = [
file.getName(),
file.getDateCreated(),
file.getUrl()
];
sheet.appendRow(data);
// Loop over files in folder, using file iterator
while (contentfiles.hasNext()) {
var file = contentfiles.next();
var data = [
file.getName(),
file.getDateCreated(),
file.getUrl()
];
sheet.appendRow(data)
}}
}
*对于任何有兴趣的人,此脚本会根据"指定的文件夹"
列出Google表格中的文件和文件夹。