Skip to content

Instantly share code, notes, and snippets.

@suntong
Last active July 21, 2018 01:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suntong/7955694 to your computer and use it in GitHub Desktop.
Save suntong/7955694 to your computer and use it in GitHub Desktop.
Get folder ID by its name
// 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
*/
@eebanos
Copy link

eebanos commented Jan 31, 2015

This isn't working for me, it works if you change line 7 as follows: folderID = folders.next().getId();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment