Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
// Iterate through the file iterator for a particular folder
function iterateFolderById() {
var files = DriveApp.getFolderById("0B5eEwPQVn6GOaUt6Vm1GVjZmSTQ").getFiles();
while (files.hasNext()) {
var file =;
var doc = DocumentApp.openById(file.getId());
doc.replaceText("My search string or regex", "My replacement string");
// Find folder by its name
function processFoldersByName() {
var folders = DriveApp.getFoldersByName("myfoldername");
var myFolder = null;
if (folders.hasNext())
myFolder =;
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,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.