Recursively renaming files

Started by ed102, February 23, 2014, 01:10:34 AM

Previous topic - Next topic

ed102

Hi

I have several thousand photos sorted in year, month, day folders all with various names and want to change the name of them all to the following format:

ed-00000.jpg, ed-00001.jpg, ed-00002.jpg etc

Using the following command in Linux

exiftool -filename='ed%-.5c.jpg' -r dir

recursively changes all files but every time it enters a new directory it starts the renaming from 00000 again.

How do I get it to continue the sequence when entering the next directory?



Phil Harvey

To do this you must change gears and use a couple of different ExifTool features:

exiftool '-filename<ed-${filesequence;$_=sprintf("%.5d",$_)}.jpg' -ext jpg -r DIR

Here I added -ext jpg just in case there are other types of files around.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

ed102

Thanks for that Phil works great but it sometimes doesn't descend into the directories in date order so the file numbering is out.

e.g. In the 2013 directory it will rename the 05 directory before 03 directory.

Is there a way to prevent this?



Phil Harvey

Unless you specify a different order, the order for a file list is system dependent (but usually alphabetical on Unix systems).

However, you can specify the order with ExifTool.  First sort on Directory, then FileName:

exiftool -fileorder directory -fileorder filename ...

I think this should do what you want.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

ed102

Cant try it right now, but that seems to be what I am after.

Thanks again for the quick help, much appreciated  :)

Ed