image filename renaming using a .BAT batchfile...

Started by ting, January 11, 2020, 02:08:41 AM

Previous topic - Next topic

ting

Hello all,

Maybe I'm looking to do the impossible here - as in running a batch file routine to rename a collection of images in a folder?

For one reason or other and, in some instances, I ended up renaming some of my existing RAW files sequentially - as in this example:

Quote
110803rc_HK_Hungry_Ghost_015.CR2
110803rc_HK_Hungry_Ghost_015.xmp
110803rc_HK_Hungry_Ghost_016.CR2
110803rc_HK_Hungry_Ghost_016.xmp
110803rc_HK_Hungry_Ghost_017.CR2
110803rc_HK_Hungry_Ghost_017.xmp

Renaming one's original picture files in this fashion maybe fine for commercial assignments, etc. As I see it, this is not particularly effective when it comes to file naming in stock photography and other uses. Maybe a personal predilection perhaps?

Anyway, long story short, I am looking to "rename" the renamed file back to this pattern:

Quote
110803rc_HK_Hungry_Ghost_4832.CR2
110803rc_HK_Hungry_Ghost_4832.xmp
110803rc_HK_Hungry_Ghost_4833.CR2
110803rc_HK_Hungry_Ghost_4833.xmp

Since these are Canon .CR2 files and, thanks to ExifTools and the ExifToolGUI apps, I can pick up the "Fileindex" number from the Metadata Maker notes - the "4832" part. That's the easy part.

What I'm doing right now is a copy and paste operation. Here I select the 110803rc_HK_Hungry_Ghost_015.CR2 file. Then, go to the Maker notes and select the corresponding Fileindex number. I then copy that and replace the _015 part. Fine if this is a one of thing.

Unfortunately, it's not. In each folder there are a 100 + images.

My question is this, is it possible to create a batch file to automate this reaming process? And, if so, how can I get this done?

Suggestions would be much appreciated.

Cheers,

Rogan

greybeard

What about:

exiftool '-filename<${filename;s/_\d+\..*//}_$fileindex.%e'  .




Hayo Baan

Since you are on Windows, change the single quote to double quotes in Greybeards command.
Hayo Baan – Photography
Web: www.hayobaan.nl

StarGeek

The one problem is that FileIndex won't appear in the XMP files and they won't get renamed.  Additionally, you would have to rename the XMP files first because if the JPG is renamed first, then the XMP can't be matched correctly.

I think this will do it
exiftool -fileOrder -Filename -TagsFromFile %d%f.jpg '-filename<${filename;s/_\d+\..*//}_$fileindex.%e'  .

It uses the -fileorder option to sort the files by filename first.  the dash before Filename tells exiftool to reverse the sort order, so the xmp files get processed first.  The only problem would be when a file extension comes after XMP, but the only file type exiftool processes normally that falls after XMP is ZIP.  So it shouldn't be a problem unless exiftool is specifically told to use a different filetype.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Hayo Baan

@stargeek, good catch! Yes, the xmps would indeed need to be treated differently and your command takes care of that very cleverly 8)
Hayo Baan – Photography
Web: www.hayobaan.nl

StarGeek

Phil gets the credit.  It's something I remember from a few years back.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Phil Harvey

It's nice to get credit for something I can't even remember.  ;)  But I do think that StarGeek is clever.

- 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 ($).