Windows Batch File Not Recognizing Set Variables

Started by ghelfrich919, August 04, 2023, 01:28:34 PM

Previous topic - Next topic

ghelfrich919

This may be more of an issue with my inexperience with creating using Windows batch files. 

I have scanned a lot of film and I want to add date/time & GPS info as possible.  I created a script that adds date/time and GPS info to these scanned photos.  I want to set variables for the info that changes (date/time/lat/long,etc) and run the script for select photos.  I created a .bat file and included a snippet below which includes 3 variables. 

When the ,bat file runs, it doesn't recognize these variables and the command fails.  see below.

Set ExifEXEC = (directorypath\exifname)
Set DateTimeOriginal = (datetime picture taken)  [ie 2023:06:13 11:00:00.00-04:00]
Set ImagePath = (image path needing processed)

%ExifExec% -ext jpg -ext jpeg -ext xmp  "-MWG:DateTimeOriginal=&DateTimeOriginal&" -P -overwrite_original_in_place %ImagePath&

C:\WINDOWS\system32>-ext jpg -ext jpeg -ext xmp  "-MWG:DateTimeOriginal=" -P -overwrite_original_in_place

'-ext' is not recognized as an internal or external command, operable program or batch file.

I also tried to read in the variables from the command line, but it also doesn't recognize the Set variables.  See below

Set ExifEXEC = %1
Set DateTimeOriginal = %2
Set ImagePath = %3

%ExifEXEC% -ext jpg -ext jpeg -ext xmp  "-MWG:DateTimeOriginal=%DateTimeOriginal%" -P -overwrite_original_in_place %ImagePath%

C:\WINDOWS\system32>-ext jpg -ext jpeg -ext xmp  "-MWG:DateTimeOriginal=" -P -overwrite_original_in_place

'-ext' is not recognized as an internal or external command, operable program or batch file.

However, when I tried to read in the variables from the command line and not Set the variables it works.  See below

%1 -ext jpg -ext jpeg -ext xmp  %2 -P -overwrite_original_in_place %3

C:\WINDOWS\system32>(directorypath)\exiftool.12.5.1.0.exe -ext jpg -ext jpeg -ext xmp  "-MWG:DateTimeOriginal=2023:06:13 11:00:00.00-04:00" -P -overwrite_original_in_place (imagepath)\2023-05-13-Lukas-01.jpg

    1 image files updated

From the research I've done, the first 2 options should work and would be my preference at this point.  I've seen other posts on this forum where others have done something similar with success.  I'm at a loss at this point.  I think it's fairly straight-forward what I am trying to do.  I'm open to other ideas/suggestions as well.

Any help would be greatly appreciated. 

Gerry

FixEUser

I just tried it with this example batch on Windows 10:

Set ExifEXEC="C:\Users\ABC\Downloads\exiftool-12.64\exiftool.exe"
Set DateTimeOriginal=2023:06:13 11:00:04.01
Set ImagePath="C:\Users\ABC\Downloads\exiftool-12.64"

%ExifEXEC% -ext jpg -ext jpeg -ext xmp  "-MWG:DateTimeOriginal=%DateTimeOriginal%" -P -overwrite_original_in_place %ImagePath%
and it worked as expected for all the sample jpg files in the ImagPath-folder.

The executed command looks like this:
"C:\Users\ABC\Downloads\exiftool-12.64\exiftool.exe" -ext jpg -ext jpeg -ext xmp  "-MWG:DateTimeOriginal=2023:06:13 11:00:04.01" -P -overwrite_original_in_place "C:\Users\ABC\Downloads\exiftool-12.64"
    1 directories scanned
    3 image files updated

Please note the syntax with the environment variables enclosed in % (percent) characters.

StarGeek

Quote from: ghelfrich919 on August 04, 2023, 01:28:34 PMC:\WINDOWS\system32>-ext jpg -ext jpeg -ext xmp  "-MWG:DateTimeOriginal=" -P -overwrite_original_in_place

'-ext' is not recognized as an internal or external command, operable program or batch file.

Bat files are not my strongest area, but these two lines show you what's going wrong. Nothing is printing for your %ExifExec% variable, so the command line is only seeing -ext as the command to run, which of course, doesn't exist, resulting in the not recognized as an internal or external command response.

Also, make sure you read FAQ #27, as that will probably be your next problem, depending upon your script.
"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

ghelfrich919

Ok, thanks for the feedback, I have figured out my issues. First, my SET statements had extra spaces before and after the = sign like the following:

   Set ExifEXEC = ....
   Set DateTimeOriginal = ...
   Set ImagePath = ....

Apparently .bat files don't like the extra spaces.  The Set statements I changed to the following:

   Set ExifEXEC=....
   Set DateTimeOriginal=...
   Set ImagePath=....

Once I did, the script ran.  I also needed to make sure I was using % around the variables.  And I needed to remove the "" from around the DateTimeOriginal value as it was fouling up the "" around the MWG:DateTimeOriginal tag. 

And thanks for the heads-up on FAQ #27.  I'm sure it will come up sometime.  :)

Gerry