我正在尝试使用谷歌脚本复制谷歌驱动器中的一些文件夹,并且我在topFolder.hasnext()行上收到错误。我已经看到了这些问题的答案,但他们并没有这样做。帮助:
TypeError: Cannot find function hasNext in object (Folder with date ID)
Why cannot Object FolderIterator find function getId?
TypeError: Cannot find function hasNext in object
我的代码是这样的:
function onOpen(){
SpreadsheetApp.getUi()
.createMenu("Hello there Click Me")
.addItem('Copy the files and folder to your specified dir','fCopier')
.addToUi()
}
var thisSheet = SpreadsheetApp.getActiveSheet();
var folderId = thisSheet.getRange("B1").getValue();
var folderId = folderId.toString().trim();
var ttopFolder = DriveApp.getFolderById(folderId);
var topFolder = ttopFolder.getFolders();
var desFolder = thisSheet.getRange("B3").getValue();
var desFolder = desFolder.toString().trim();
var reallyDesFolder = DriveApp.getFolderById(desFolder);
var forFilelist = ttopFolder.getFiles();
var topper = [];
while(topFolder.hasnext()){
topper.push(topFolder.next());
}
var filer = [];
while(forFilelist.hasNext()){
filer.push(forFilelist.next())
}
function fCopier(){
for (var i = 0; i < topper.length; i++) {
var finalfolders = topper[i];
}
var folderCompleto = reallyDesFolder.createFolder(finalfolders);
for(var j =0; j<filer.length; j++){
var finalfiles = filer[j];
}
var fileCompleto = finalfiles.makeCopy(reallyDesFolder);
}
我不明白为什么它找不到hasnext函数,因为在gs文档中它是这样的:
var folders = DriveApp.getFolders();
while (folders.hasNext()) {
var folder = folders.next();
Logger.log(folder.getName());
}
答案 0 :(得分:-1)
该函数是hasNext,而不是hasnext。你有一个错字。