I need to rename image files in a Google Drive folder
I have a Google Sheet with 2 columns, old name and new name
I would like to rename the files within the same folder using AppsScript and the sheet content as input
Thanks for your help
I need to rename image files in a Google Drive folder
I have a Google Sheet with 2 columns, old name and new name
I would like to rename the files within the same folder using AppsScript and the sheet content as input
Thanks for your help
If I understand this correctly, you want change names of the files in a Drive folder according to some sheet data (current name is in column A, and new name is in column B).
If that's the case, I'd suggest the following:
getRange().getValues().const SPREADSHEET_ID = "SPREADSHEET_ID"; // Change according to your preferences
const SHEET_NAME = "Sheet1"; // Change according to your preferences
const FOLDER_ID = "DRIVE_FOLDER_ID"; // Change according to your preferences
function changeFolderNames() {
const ss = SpreadsheetApp.openById(SPREADSHEET_ID);
const sheet = ss.getSheetByName(SHEET_NAME);
const folder = DriveApp.getFolderById(FOLDER_ID);
const values = sheet.getRange("A2:B" + sheet.getLastRow()).getValues(); // If there's no header row, use "A:B" instead
values.forEach(row => {
const [oldName, newName] = row;
const fileIter = folder.getFilesByName(oldName);
while (fileIter.hasNext()) {
const file = fileIter.next();
file.setName(newName);
}
});
}