Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save suntong/7938320 to your computer and use it in GitHub Desktop.
Save suntong/7938320 to your computer and use it in GitHub Desktop.
// Iterate through the file iterator for a particular folder
function iterateFolderById() {
var files = DriveApp.getFolderById("0B5eEwPQVn6GOaUt6Vm1GVjZmSTQ").getFiles();
while (files.hasNext()) {
var file = files.next();
Logger.log(file.getName());
var doc = DocumentApp.openById(file.getId());
doc.replaceText("My search string or regex", "My replacement string");
}
Logger.log("Done")
}
// Find folder by its name
function processFoldersByName() {
var folders = DriveApp.getFoldersByName("myfoldername");
var myFolder = null;
if (folders.hasNext())
myFolder = folders.next();
if (myFolder !== null) {
// do stuff
} else {
// exit gracefully
}
}
// 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)
// By 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