Made an error, need to recreate file extensions

Started by Henrik Jordahn, March 06, 2011, 11:17:17 AM

Previous topic - Next topic

Henrik Jordahn

So, I made a mistake. I may be using Linux (Ubuntu) and know quite a bit, but I am seemingly not immune to typos, and not well versed in regular expressions.


I played with a small number of unimportant copies to string together the exiftool command that would rename my photos as I want them, and I came up with this:

exiftool -r '-filename<${ShutterCount}_${CreateDate}' -d %Y-%m-%d_%H:%M:%S%%-c.%%e /media/NEF_STORE/

The problem is that when I went and typed in the command on the machine with all the photos, I omitted a '.' and wrote this:

exiftool -r '-filename<${ShutterCount}_${CreateDate}' -d %Y-%m-%d_%H:%M:%S%%-c%%e /media/NEF_STORE/

and all the files that got changed (46911 of them, both NEF and JPG) now have this format:
2844_2004-08-21_11:44:31NEF with no file extension. Very close to what I wanted, but not quite right.

What I think would do the trick is to use 'rename' and an appropriate regex to find all files that
1) has no '.'
2) ends in either NEF/nef or JPG/jpg
and then renames the file by discarding the last three characters and replacing them with a '.' and the last three characters.

But I don't know how to build that regex, can anyone here give me a hint?

Phil Harvey

#1
ExifTool to the rescue!:

exiftool -r -ext '' -if '$filename=~/(jpg|nef)$$/i' -filename=%-.3f.%-3f DIR

- Phil

Edit:  There.  I'm done tweaking the command now
...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 ($).

Henrik Jordahn

Thank you very much, on top of developing a very neat tool you also provide fast feedback. I shall look into this after dinner.