0

I am in need of a solution that will allow me to batch reformat/rename the date appended at the end of a filename and then move the date to the beginning of the filename. I'm adopting the ISO 8601 standard (yyyy-mm-dd).

After searching the web for a solution and tinkering with Automator, I haven't found a solution.

Example 1:
Current Filename: Statement 01-07-2019
Desired Filename: 2019-01-07 Statement

Example 2:
Current Filename: 01-07-2019 Statement
Desired Filename: 2019-01-07 Statement
  • The second example doesn't match the description in the question, which part is correct? – nohillside Jan 11 at 16:44
1

There are various options to mass rename files on MacOS:

I'll go with the terminal option here.


  1. Install HomeBrew if you don't have it already.
  2. From your Terminal, enter: brew install rename
  3. From your Terminal, go to the folder where all your files to be renamed are
  4. Enter the two commands below. The first one is for your Example1 case. The second one for your Example 2 case.

Note: Those two commands will not affect your file names. Their only purpose is to check.


rename -n 's/^([^""]+)( )(\d{2})-(\d{2})-(\d{4})(.*)$/$5-$4-$3 $1$6/' *

rename -n 's/^(\d{2})-(\d{2})-(\d{4})(.*)$/$3-$2-$1$4/' *

You should get results similar to:

'Statement 01-07-2019' would be renamed to '2019-07-01 Statement'

'01-07-2019 Statement' would be renamed to '2019-07-01 Statement'

After you checked everything is ok, remove the -n option to effectively rename your files:

rename 's/^([^""]+)( )(\d{2})-(\d{2})-(\d{4})(.*)$/$5-$4-$3 $1$6/' *

rename 's/^(\d{2})-(\d{2})-(\d{4})(.*)$/$3-$2-$1$4/' *

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.