Main Menu

Batchfile EXIFTOOL

Started by esdoublelef, April 01, 2021, 12:27:24 AM

Previous topic - Next topic

esdoublelef

Hi all,

need help for a batch file for Exiftool in windows. i tried deepsearching other posts in this forum but I couldn't find a simple solution. (Btw, i noted in another post to NOT name my batchfile as exiftool.bat because it loops endlessly. brilliant stuff by Mr Phil Harvey. it's now copyexif.bat)
I have converted a batch of RAW (RAF) files to JPG (my magick code below).
And I'm sure a lot of people have the same problem - I would like to copy the EXIF data from the RAW (RAF) to JPG.
I renamed the exif(-k).exe file to exif.exe and

Here is my batch code:

@ECHO ON
  FOR %%G IN (*.RAF) DO exiftool.exe -tagsfromfile %%G -all:all %%~dpnG.jpg
PAUSE


But i keep gettting a "file not found" error, and the EXIF information is not copied over.
Can someone point out to me what's wrong with my code?






Btw, my batch code for magick from RAW(RAF) to JPG is

@ECHO ON
  FOR %%a in (*.RAF) DO magick %%a -set colorspace RGB -colorspace sRGB -quality 100%% "%%~na".jpg
PAUSE

I feel like i should share it here because I didn't include the "colorspace" at first, making all the conversions very dark. This made perfect sense, and i got it from a comment off twitter. If anyone thinks i should improve this batch code, please feel free to criticize/contribute!!
Thank you!

StarGeek

Don't loop exiftool.  It's biggest performance hit is the startup time and looping it like that can take a very long time.  Exiftool has very powerful batch abilities that are much faster. See Common Mistake #3.

Instead, after you've run all the ImageMagick commands, just point exiftool to the files and let it do all the batch stuff itself.  Since I'm guessing that the converted jpegs are in the same directory as the RAF files, then you could use this command
exiftool -ext jpg -TagsFromFile %d%f.raf -all:all /path/to/files/

For every jpg in the /path/to/files/ directory, exiftool will look for a matching RAF file with the same base name and then copy all tags from the RAF to the jpg.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

esdoublelef

Hi! Thanks for the advise on not to use loops! noted on the hit on the performance.

Really sorry but i'm not sure what to do with the /path/to/files/ part. am i supposed to change that to the directory that the files are in? I tried doing that but it gives me an error still. (i tried running exiftool from the cmd in the directory itself)

otherwise does it make sense for me to write a .bat, no loop, just the code you posted, but it works in any directory that i copy this .bat file to?

Thank you!

esdoublelef

Hi!

I ran something that made it work. in CMD i ran the following line

exiftool -tagsfromfile %d%f.RAF -ext JPG "F:\Photos\unsorted\folder\raf keep exif test"

turns out i gotta put apostrophes to the directory. should this be documented? i couldn't for my life get it to work until i put the "" signs.

Is this code correct now stargeek?

regards,
sam

Quote from: StarGeek on April 01, 2021, 12:46:44 AM
Don't loop exiftool.  It's biggest performance hit is the startup time and looping it like that can take a very long time.  Exiftool has very powerful batch abilities that are much faster. See Common Mistake #3.

Instead, after you've run all the ImageMagick commands, just point exiftool to the files and let it do all the batch stuff itself.  Since I'm guessing that the converted jpegs are in the same directory as the RAF files, then you could use this command
exiftool -ext jpg -TagsFromFile %d%f.raf -all:all /path/to/files/

For every jpg in the /path/to/files/ directory, exiftool will look for a matching RAF file with the same base name and then copy all tags from the RAF to the jpg.

Phil Harvey

That is correct.  You need double quotes around arguments that contain spaces.  This is a requirement of the shell in which you are running exiftool (Windows cmd.exe I assume).

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

StarGeek

The lack of quotes is probably the source of your original "file not found".  You do have the quotes around the filename part in the ImageMagick command.

Also, in case you move the exiftool command to your batch file, double the % signs.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

esdoublelef

Thank you and last question!

so i did put it into a .bat file and thanks for your help it now looks like this (no loop)

@ECHO ON

exiftool -tagsfromfile %%d%%f.RAF -ext JPG "F:\Photos\unsorted\folder\RAF to JPG converter"

PAUSE


is there any way to make the directory "" follow the current directory that the .bat file is in? so that it can be copied and pasted to other folders and the .bat file can do the EXIFtool magic any where?

thanks again!


StarGeek

That would be a batch file question.  Take a look at this StackOverflow answer.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Alan Clifford

Wouldn't that just be

exiftool -tagsfromfile %%d%%f.RAF -ext JPG .

that is, replace the path to files with a full stop.

And then: 

  • copy the batch file to the directory where the files are

  • change to that directory at the command prompt.

StarGeek

@Alan, Probably.  But I would still use -All:All as otherwise it would default to meaning -All which isn't the same.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Alan Clifford

Quote from: StarGeek on April 01, 2021, 04:20:02 PM
@Alan, Probably.  But I would still use -All:All as otherwise it would default to meaning -All which isn't the same.

I was trying to answer the path question rather change the exiftool arguments.  I should be more careful.

esdoublelef

oh! the full stop worked just great!

thanks so much for all your help Alan, Stargeek and Phil!

Quote from: Alan Clifford on April 01, 2021, 03:10:14 PM
Wouldn't that just be

exiftool -tagsfromfile %%d%%f.RAF -ext JPG .

that is, replace the path to files with a full stop.

And then: 

  • copy the batch file to the directory where the files are

  • change to that directory at the command prompt.