I've found some code here that almost does what I need, but I'm trying to break the recursive function when I locate the folder in question. Currently, my console.log returns "undefined."
This is probably something easy; I just can't see it.
Here's my (mostly stolen) code:
function moveFile(e) {
var FileNo = e.parameters.FileNo;
var destFolder = e.formInput.input_field;
// Get the Folder
var Folders = DriveApp.searchFolders("title contains '"+FileNo+"' and trashed = false and hidden = false");
var Folder = Folders.next().getId();
var url = start(Folder, destFolder);
console.log(url);
}
function start(FolderID, destFolder) {
folder = DriveApp.getFolderById(FolderID);
var response = listFolders(folder, destFolder);
//console.log(response);
return response;
}
function listFolders(folder, destFolder) {
//starting point, we come here from start() or from the bottom of this function
var destFolder = destFolder;
//check the name
var name = folder.getName();
if (name.match(destFolder)) {
//console.log(folder.getUrl());
var response = folder.getUrl();
return response;
}
//now see if this folder has subfolders
var subfolders = folder.getFolders();
//if it has, we call this function again
while (subfolders.hasNext()) {
listFolders(subfolders.next(), destFolder);
}
}
Thank you to whomever feels generous enough to save this tired parent from himself.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.