Renaming files using a .bat file

Started by sjw, February 09, 2023, 09:59:13 AM

Previous topic - Next topic

sjw

Hi,
When editing files I often prefer to have a folder and a group of predefined commands in a .bat file - and I drag a folder into the .bat file for processing.
I have a command I want to use like this - but I must be doing something wrong..  I'm sure it's something stupid!..
The command is a simple file rename from the Date Taken data:
c:\users\ste\exiftool "-FileName<DateTimeOriginal" -d "IMG_%Y%m%d_%H%M%S%%-c.%%le" -r <file or folder name>This works fine from CMD - however, when I put it in a .bat file and change the file or folder name to %* I doesn't do anything.
c:\users\ste\exiftool "-FileName<DateTimeOriginal" -d "IMG_%Y%m%d_%H%M%S%%-c.%%le" -r %*What am I doing wrong - I suspect related to %* at the end?
I wasn't sure if the -r was affecting things (as no directory name is specified as such) but it didn't make any difference.

Phil Harvey

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

StarGeek

Almost certainly FAQ #27, but it helps significantly to see actual output.  Saying only "It doesn't work" will always get a "It works here" response from me. ;)

The %* is a "variable" in Windows bat files which will hold all the arguments supplied to the bat.  In the case of drag/droping files onto the bat file, the full file paths for those files will be supplied, including quotes for the files that need it, i.e. have spaces in them.

The percent sign is not doubled for %*, just for the ones in the exiftool command.
* 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).

sjw

#3
Sorry, yes, I could have changed the bat to pause but didn't think at the time.  It worked fine in the normal command but scrolled through quickly and (obviously) disappeared in the bat.
Yes, it was indeed FAQ 27 - many thanks for both your help!
For future reference, the working code (within a .bat file) is:
c:\users\ste\desktop\exiftool "-FileName<DateTimeOriginal" -d "IMG_%%Y%%m%%d_%%H%%M%%S%%%%-c.%%%%le" -r %*