Google Apps Script, DriveApp
I had an unexpected need to change some non-native file names – in my case, MS Word docs – to something else to appease my masters. Being the resident Igor, I delighted in the task.
I had a folder of MS Word documents on my Google Drive that needed to all be renamed. They all needed the same name with an index number to distinguish that they were different files.
There were, however other file types in the folder.
The problem with non-native files in Google Drive is that it’s a little tricky to find their ID. Besides I just wanted to change ALL files that were MS Word in the folder.
What I would need to do is search for all files inside my selected folder that are of MS Word type and rename them with the same name but with a counter at the end. For example:
Continue reading “Google Apps Script – How to Change the File Name of Non-Native Files like MS Word Docs, PDF’s and Excel files.”
|Old File Name||New File Name|
Google Apps Script
One of my recent projects in Google Apps Script required me to search for a file by name and get its ID. This can be problematic in Google Drive because you can have multiple files of the same name in multiple locations. My solution was to also check the file’s parent folder name as well.
I created a function
getFileByName() to handle this. The function takes the following parameters:
fileName – The name of the file you are looking for. (required)
fileInFolder – The parent folder of the file your are searching for. (optional)
The file path would look a little something like this:
getFileByName() returns an object containing :
- the ID of the file if the file exists or
false if it does not.
- the ERROR if there is an error or
false if there is not.
The returned object would look like the following:
"error":"There is more than one parent folder: Logo for file
getFileByName() reports the following errors:
- If no parent folder name is given and there are more than one file with the same file name.
- There is more than one parent folder and file combination with the same name.
- There are multiple files with the same name but none are in the folder parent name provided.
- No file with the file name provided exists.
Continue reading “Google Apps Script: Get File By Name – With Optional Parent Folder Crosscheck”