我编写了一个代码应用脚本,将所有文件夹名称和文件名称列出到电子表格中,直到我重命名其中一个文件夹或文件之前,该电子表格都可以正常工作。然后,下次我运行该脚本时,它将不会将重命名的Folder / File包含在Spreadsheet中。我在脚本中做错了什么吗? 预先感谢您的帮助。
链接到电子表格:https://docs.google.com/spreadsheets/d/1T3eKmyXKhLCbcoMdZRzMQ1__-dL3bTlH0wMKaWVFJ1Y/edit?usp=sharing
链接到Google脚本:https://script.google.com/d/1LVTe29Y3jDbElt8LM4ciZ8Kj0gPzmFAxawZaYmRaFvkkfrewtJ5fxO0B/edit?usp=sharing
链接到文件夹:https://drive.google.com/drive/folders/1VPQC9Cp4QT0r_ILmq9c0nOsSSduqh6jg?usp=sharing
function listFolders(folder) {
var ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/1T3eKmyXKhLCbcoMdZRzMQ1__-dL3bTlH0wMKaWVFJ1Y/edit#gid=0');
var first = ss.getSheetByName("Sheet1");
first.clear("A2:D405");
var sheet = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/1T3eKmyXKhLCbcoMdZRzMQ1__-dL3bTlH0wMKaWVFJ1Y/edit#gid=0');
sheet.appendRow(["File Name", "URL", "Folder Name"]);
var folder = DriveApp.getFolderById('1VPQC9Cp4QT0r_ILmq9c0nOsSSduqh6jg');
var subfolders = folder.getFolders();
while (subfolders.hasNext()) {
//Logger.log(folder);
var name = subfolders.next();
while (subfolders.hasNext()) {
//Logger.log(folder);
var name = subfolders.next();
var files = name.getFilesByType('application/vnd.google-apps.spreadsheet');
var cnt = 0;
var file;
while (files.hasNext()) {
var file = files.next();
cnt++;
Logger.log(file);
Logger.log(cnt);
data = [
file.getName(),
file.getUrl(),
name, //folder name
];
sheet.appendRow(data);
};
}
}
}