length
folders
. hasNext()
.
Google -
var folder,folders;
folders = DriveApp.getFolders();
while (folders.hasNext()) {
folder = folders.next();
Logger.log(folder.getName());
}
, :
function InsertFileToFolder() {
var file,folder,
folderIdOrFalse;
file = DriveApp.getFileById(copyId);
folderIdOrFalse = folderExists();
if (folderIdOrFalse !== false) {
folder = DriveApp.getFolderById(folderIdOrFalse);
} else {
folder = DriveApp.createFolder("testFolder");
}
folder.addFile(file);
};
function folderExists() {
var folders = DriveApp.getFolders();
var theReturn = false,
i=0,
folderName = "",
folder;
while (folders.hasNext()) {
folder = folders.next();
folderName = folder.getName();
if (folderName === 'testFolder') {
theReturn = folder.getId();
break;
};
};
return theReturn;
};