I have a folder containing files like
ABC – 2001
DEF
EFG – 2001-2002
HIJ
KLM – 2003
NOP
QRS – 2004
I want to add the year to all file names that currently have no year suffix. The suffix should always be the one of the last file with a year suffix: EFG
contains 2001 and the start of 2002, so HIJ
needs the suffix 2002.
How could I do this?
Best Answer
This should do it for the file names you have given. It assumes that the name part consists of uppercase letters, spaces, and dashes. And in the case of two years present, that they are separated by a dash. Also, it assumes that the first file does contain a year (otherwise it has nothing to deduct it from), and it will process every file present in the directory.
Copy&paste to the Terminal, and if you want to check first that it will do it correctly, add an
echo
before themv
.