Last active
July 21, 2018 01:22
-
-
Save suntong/7955694 to your computer and use it in GitHub Desktop.
Get folder ID by its name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get the *first* folder ID by its name | |
function getFolderByName(folderName) { | |
var folders = DriveApp.getFoldersByName(folderName); | |
var folderID = null; | |
if (folders.hasNext()) | |
folderID = folders.next(); | |
return folderID; | |
} | |
/* | |
if you have multiple folders with the same name, you would have | |
to iterate through them in a while loop similar to the file | |
iterator in the code you linked) and find a marker that proves | |
this is the folder you are looking for (i.e. you could have an | |
empty file with a particular name in there) | |
-- patt0 | |
http://stackoverflow.com/questions/20510314/find-replace-in-files-within-a-folder-using-google-apps-script | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This isn't working for me, it works if you change line 7 as follows: folderID = folders.next().getId();