I have over 100+ google drive folders I would like to update the name using GAS. I use this code below but when I tested it, the folder name changes to "undefined". Is .setName() correct method to use or do I need to copy the folder and rename it to accomplish this?
- FolderID is listed in Column A
- FolderName (new foldername) is listed in Column B
Updated? is in Column C to denote if row has completed.
function renameFolderName(){ var s = SpreadsheetApp.openById("sheetIDhere").getSheetByName('TEST'); var id = s.getRange(2,1,s.getLastRow()).getValues(); var foldernames = s.getRange(2,2,s.getLastRow()).getValues(); var updated = "Yes"; for (a = 0; a < id.length-1; a++){ for (b = 0; b < foldernames.length-1; b++) { var folderlocation = DriveApp.getFolderById(id[a][0]).setName(foldernames[b][1]); s.getRange(a+2,3).setValue(updated); } } }
The current test changes the folder name to "undefined" but actural result should be whatever the value that is listed in column B.