I am working on a script in App Script that will change the file name of all the files in a certain folder based on their creation date using this format yyyy_MM_dd_filename
. I was able to create the script and it is working when I run it however everytime I run it again it appends another date on the file name which makes it duplicated.
What I wanted to happen is that when I run the script with a new file it will not change the file name of those who have already the date format that I created but instead just changed those that was just saved and newly uploaded in Google Drive.
This is my code:
function changeName() {
var folder_access = DriveApp.getFolderById("1qSQ-K2R97PIfDHztmU0iwM0y_GxPk2zG");
var folder_files = folder_access.getFiles();
var file_name = folder_files.next();
var filename_format = Utilities.formatDate(new Date(file_name.getDateCreated()), "GMT", "yyyy_MM_dd");
file_name.setName(filename_format+"_"+file_name);
}