我一直在尝试创建一个谷歌应用脚本,列出我的驱动器中的所有文件以及大小,并通过电子邮件发送给我。部分这是实践,可能有用。到目前为止,这是我的代码:
function listAllFiles () {
var rootFolder = DocsList.getRootFolder();
var contents = rootFolder.getFiles();
var file = DocsList.getAllFiles();
for (i = 0; i < contents.length; i++) {
Logger.log(file[i].getName() + ":::" + file[i].getSize());
}
var recipient = Session.getActiveUser().getEmail();
var subject = 'A list of files in your Google Drive';
var body = Logger.getLog();
MailApp.sendEmail(recipient, subject, body);
}
它只发送大约5个文件的列表,除非我将“contents.length”更改为100之类的手动编号。(由于某种原因,如果我将其设置为1000,则会在.getName上抛出错误) 。无论如何,我知道我不应该使用硬数字。请忍受我的无知,我一直在学习谷歌脚本大约1周,javascript约2个月我自己。
答案 0 :(得分:0)
尝试
function listAllFiles () {
// DriveApp is recommended rather than DocsList.
var dFiles = DriveApp.getFiles();
while (dFiles.hasNext()) {
var thisFile = dFiles.next()
Logger.log(thisFile.getName() + ":::" + thisFile.getSize());
}
// you might want to make this restartable if you have lots of files ... time out
var recipient = Session.getActiveUser().getEmail();
var subject = 'A list of files in your Google Drive';
var body = Logger.getLog();
MailApp.sendEmail(recipient, subject, body);
}