Batch Reformat Date in Filenames 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
There are various options to mass rename files on MacOS:


Automator, Apple Script
Third-party Applications (Metamorphose2, Name Changer, Inviska Rename, A Better Finder Rename, Renamer, File Renamer, ...)
Terminal


I'll go with the terminal option here.




Install HomeBrew if you don't have it already.
From your Terminal, enter: brew install rename
From your Terminal, go to the folder where all your files to be renamed are
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/' *