Unique XMP value script not working on Windows any advice?

Started by mc-digitizer, August 28, 2024, 03:03:22 PM

Previous topic - Next topic

mc-digitizer

I had a script to embed the filename minus the extension as a the XMP: Title Value field and it was working back in April. Now for whatever reason it's failing but I haven't changed the script. Does anyone have any thoughts on what is going wrong. Also if you have any ideas on a more efficient way of doing this, I'm all ears.

Here's the code:

@echo off
setlocal enabledelayedexpansion

rem Set the path to ExifTool
set exifTool="C:\exiftool\exiftool.exe"

rem Set the path to the directory containing the photos (including subdirectories)
set photoDir="E:\PhotoDir\SubPhotoDir"

rem Set the maximum number of characters for the XMP:Title value
set maxLength=35

rem Loop over each file in the directory (including subdirectories)
for /r "%photoDir%" %%f in (*) do (
    echo Processing file: %%f
    rem Set the XMP:Title value for this file
    set "titleValue=%%~nf"
    set "titleValue=!titleValue:~0,%maxLength%!"
    echo Title value: !titleValue!

    rem Run ExifTool to write the XMP:Title value for this file
    %exifTool% -overwrite_original -XMP:Title="!titleValue!" "%%f"
)

rem Display the number of files processed
msg * "The script has completed. %errorlevel% files were processed."

Any advice is much appreciated!

StarGeek

I don't know why your script would stop working, but you don't want to loop exiftool, as its biggest performance hit is the startup time (see Common Mistake #2).

You can do this with a single exiftool command
exifTool -overwrite_original "-XMP:Title<${Basename;$_=substr($_, 0, 35)}" /path/to/files/
"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