Can you rename a raw file and create tag in XMP file at the same time?

Started by Ad_Astra, February 06, 2025, 06:43:00 AM

Previous topic - Next topic

Phil Harvey

Quote from: Ad_Astra on February 09, 2025, 02:01:55 PM1) add the PreservedFileName to the JPEG files. As there is no XMP file for JPEGs do I just update the PreservedFileName tag directly in the JPEG file? I.e. is it safe and does not cause the picture data to be recompressed and lose of image quality?

ExifTool doesn't change the image data.

Quote2) add a copy number in case of duplicates. As I include original file name I don't think it should happen but to be safe does this "-filename<myname_${subsecdatetimeoriginal;}_%f%+nc.%le" add -1 -2 etc only if there are duplicates?

%-c will give you NAME.EXT and NAME-1.EXT if you have 2 files with the same name.  If you wanted NAME-1.EXT and NAME-2.EXT instead, things would be more difficult.

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

Ad_Astra

Thanks Phil, would %-nc be sufficient to create NAME-1.EXT and NAME-2.EXT?

Phil Harvey

%-nc will give NAME.EXT and NAME-2.EXT.

%-.nc will give NAME-1.EXT and NAME-2.EXT.

But %-.nc will also give NAME-1.EXT for a file that doesn't isn't a duplicate.  And you said you wanted only duplicate files to have the copy number.

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

Ad_Astra

Hi

I have been trying to add another tag to the initial XMP file.

Original code was
Quoteexiftool -P -overwrite_original -wm cg "-XMP:PreservedFileName<Basename" -srcfile %d%f.xmp -ext nef

I wish to update the XMP Title tag to the new name without extension, whilst the file has not been renamed yet with the command above I do know how I am going to rename it so I tried the following:

Quote-P -overwrite_original -wm cg "-XMP:PreservedFileName<Basename" -d %Y%m%d_%H%M%S-%-3f -tagsfromfile %d%f.NEF "-XMP-dc:Title<myname_${subsecdatetimeoriginal;}_%f" -srcfile %d%f.xmp -ext nef

This created a tag value with %f

Quote<dc:title>
   <rdf:Alt>
    <rdf:li xml:lang='x-default'>myname_20250121_094041-690_%f</rdf:li>
   </rdf:Alt>
  </dc:title>

I was please the date and time worked but puzzled why the original name part is just the text %f. Replacing %f with Basename did not work either. Any suggestions please what I am doing wrong?

edit updated code to remove Windows escape char.

StarGeek

The %f filename variable can only be used with specific commands. It is not a variable that can be copied into another tag. For that, you have to use either Basename or Filename
"-XMP-dc:Title<myname_${subsecdatetimeoriginal;}_$Filename"

Oh, I have a copy/paste for this that I forgot about

The percent tokens such as %d, %f, %e, etc, can be used in assigning a value to the Filename or Directory pseudo-tags (see Writing "FileName" and "Directory" tags) and in these options
-TAG<=DATFILE option
-TagsFromFile option
-w (-TextOut) option
-W (-TagOut) option
-o (-out) option
-srcfile option
"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

Phil Harvey

(to summarize: the %f filename format code may only be used in places where a file name is expected)

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

Ad_Astra

Thanks Phil and StarGeek, %f is the wrong thing to use and I missed the $ sign out when I tried Basename so this now works in my script:

"-XMP-dc:Title<myname_${subsecdatetimeoriginal;}_$Basename"