我试图复制到步骤 https://ctrlq.org/code/19854-list-files-in-google-drive-folder谷歌脚本应用程序列表驱动器文件夹
它成功地在表中的列标题,但没有得到/打印的任何数据行。我哪里做错了?
这是我有:
/* Code written by @hubgit
https://gist.github.com/hubgit/3755293
Updated since DocsList is deprecated
*/
function listFilesInFolder(folderName) {
var folder = DriveApp.getFoldersByName(folderName).next();
var contents = folder.getFiles();
var file, data, sheet = SpreadsheetApp.getActiveSheet();
sheet.clear();
sheet.appendRow(["Name", "Date", "Size", "URL", "Download", "Description", "Type"]);
for (var i = 0; i < contents.length; i++) {
file = contents[i];
if (file.getFileType() == "SPREADSHEET") {
continue;
}
data = [
file.getName(),
file.getDateCreated(),
file.getSize(),
file.getUrl(),
"https://docs.google.com/uc?export=download&confirm=no_antivirus&id=" + file.getId(),
file.getDescription(),
file.getFileType().toString()
];
sheet.appendRow(data);
}
};
感谢,
您需要调试代码。 'listFilesInFolder'函数是否接收到'folderName'?在函数的最顶端添加这行代码:'Logger.log('folderName:'+ folderName);'。运行代码,然后在VIEW菜单中选择LOGS。日志中是否打印了正确的文件夹名称? –
谢谢@SandyGood。使用添加的部分运行时,我遇到了新的错误。 无法检索下一个对象:迭代器已到达结尾。 (第8行,......) – rin
每当我试图找到一个新的解决方案时,都会出现一个新的错误,如果使用docList,它会被折旧,如果我使用while(contents.hasNext()){ ( – rin