我正在尝试使用Google脚本的DriveApp folderIterator访问子文件夹,但是无法正确读取子文件夹。
例如,我的驱动器具有以下结构:
+Root
+High School
+Class Material
-File1
-File2
+Books
function test(){
var folderIter = DriveApp.getFoldersByName("High School");
var folder = folderIter.next();
printFolder(folder);
}
function printFolder(folder){
var folderIter = folder.getFoldersByName("Class Material");
while (folderIter.hasNext()) { // always returning false
var file = folderIter.next();
Logger.log(file.getName());
}
}
我的while循环中的条件在应读取文件夹“ Class Material”时总是返回false
任何帮助将不胜感激!
编辑:与我共享的文件夹,多个具有相同名称的文件夹是一个问题。
答案 0 :(得分:0)
尝试一下。
function test(){
var folderIter = DriveApp.getFoldersByName("High School");
var folder = folderIter.next();
printFolder(folder);
}
function printFolder(folder){
// get folders under High School
var folders = folder.getFolders();
while( folders.hasNext() ) {
var subFolder = folders.next();
if( subFolder.getName() === "Class Material" ) {
// what every you want to do with subFolder
return;
}
}
}