What tools exist to rename (truncate) batches of files in OS X

automatorfinderterminal

I get bunches of files I need to rename. The original filenames normally have 7 digits – plus an optional character (or two), followed by a space then a whole string of other characters. I need to rename them to be such that the space and everything after it is replaced by '-z'.

For example: (original filenames)

3543679 ggry Hugh highs Bhutto.jpg

6789456 hfghh hfghh death.eps

8753674a hfryg gyjbff hfghh.png

4686536c Guggenheim.jpg

Would become: (renamed filenames)
3543679-z.jpg

6789456-z.eps

8753674a-z.png

4686536c-z.jpg

Anyone got any ideas how to automate this?

Best Answer

Try running something like this in Terminal:

cd ~/Some\ folder
for f in *; do mv "$f" "${f/ *./-z.}"; done