Apple - Renaming files/names in bulk, any smarter solution?
- export into a CSV (unicode UTF-8 or any other 8bit encoding, not UTF-16): two columns, separated by
;(assuming there is no
;in a file name)
- open Terminal
- change to folder containing the files
perl -pi -e 's/\r\n/\n/;' LISTOFNAMES.csvto fix CRLF issues
while IFS=\; read old new; do mv "$old" "$new"; done < LISTOFNAMES.csv
PS: This will overwrite existing files if the new name already exists.
PPS: Test this on a temporary folder with just a few files first (and make sure you have a recent backup)
I've found this to be one of the most simple ways:
- In a spreadsheet column, concatenate: "cp oldfilename newfilename" to create a copy with the new name.
- Use "mv oldfilename newfilename" to replace the old files rather than copy.
- Copy this concatenated column to a text file and save as rename.sh in the folder with the files to be renamed.
- Open terminal, navigate to the folder with the files to be renamed and run bash rename.sh
A couple years back I wrote a blog post on performing bulk file operations. The first step was to copy the list of files from search results into a spreadsheet. Since you already have the spreadsheet, you are very close to having a script that can do the renaming for you.
Let’s assume you have old names in column A and new names in column B.
Write the following into the first cell of column C:
Write the following into the first cell of column D:
Write the following into the first cell of column E:
Instruct spreadsheet application to “Fill > Down” column C, D and E.
Then copy all data rows from columns C, D and E. Paste the copied text into a text editor. You should get row reading:
mv "old file name" "new file name"
This command will move/rename the file named “old file name” to “new file name”. Warpping the file names in double quotes allows for file names containing spaces.
If you are satisfied with the commands, copy-paste the complete text to the shell in Terminal.app
The procedure is admitedly less elegant that having a script process your spreadsheet or CSV. It however has the advantage of you getting a chance to double-check the commands before running them. When working from search results, you can easily get values from other columns (e.g. modification date, image dimensions, etc.) and work these into the new file names.