I am attempting to rename every file in a specified folder and all files in all subfolders but I cannot figure out how to do so. I so far have this script that renames every file in a folder given its Id, but I need to do all subfolders.
function renameFilesInFolder(folderID) {
var folder = DriveApp.getFolderById(folderID)
var files = folder.getFiles(),
fileNames = []
while(files.hasNext()){
var file = files.next()
var oldFileName = file.getName()
var checkIfMatch = oldFileName.substring(oldFileName.length - 3);
var newFileName = ""
if (checkIfMatch=="OBS"){
newFileName = oldFileName
} else {
newFileName =oldFileName+"_OBS"
}
file.setName(newFileName)
Logger.log(newFileName)
}
}