Search code examples
cmdrenamewildcardbulk

Batch/Bulk rename of folders/directories with wildcards [windows or linux]


Hello I have a directory for my photos in the structure of

Pictures/year/month/[dd/mm/yyyy]_description.

Sometimes I did not use [dd/mm/yyyy] but [dd/mm/yy] for example [22-03-13] instead [22-03-2013].

I need to rename all of this with a command because there are a lot to change it by hand.

I was able to find them by using "Everything" finder with the

"E:\Pictures\" [??-??-13]_*

I would love a command like:

rename [??-??-13]_* to [??-??-2013]_*

where ? and * remain the same. Is this possible? Thank you very much for your time.

PS I can use either Linux or Windows.


Solution

  • Many linux distros come with a great tool called rename that does just what you want.

    For example:

    $ rename -n 's/(\d{2})-(\d{2})-(\d{2})_(.*)/$1-$2-20$3_$4/' ./*
    './08-01-14_tahiti.jpg' would be renamed to './08-01-2014_tahiti.jpg'
    './14-11-13_guam.jpg' would be renamed to './14-11-2013_guam.jpg'
    './23-07-12_hawaii.jpg' would be renamed to './23-07-2012_hawaii.jpg'