Copy data from matching file with unknown extension

Started by Martin Z, October 03, 2024, 06:13:20 AM

Previous topic - Next topic

Martin Z

SG Edit: Split from this old thread

Quote from: StarGeek on April 19, 2017, 11:03:32 PMTry something like this
exiftool -tagsfromfile /path/to/source/files/%f.MP4 -ext MKV TargetDirectory
This example assumes that the source files are MP4s and the targets are MKVs.  Change as needed.  Also, double check to make sure that exiftool can actually copy the tags, as not all video tags can be copied.

Thanks, this was exactly what I needed too!

Well, not quite but gets me most of the way there... can this be tweaked so that it can work without knowing the source extension type?

I have a script that bulk upscales images, always generating parallel JPG files in a separate directory, and then uses EXIFTOOL to copy the metadata to the upscaled images. So for every file.xxx in the source there will be file.jpg in the target directory, however I could run this script to upscale a folder of JPG's, PNG's, or other images -- so there will always be a matching file with the same name, but I won't know what extension it is.

Is this possible?

StarGeek

You would have to have a duplicate -TagsFromFile option for each file extension

exiftool -tagsfromfile /Source/Path/%f.jpg -tagsfromfile /Source/Path/%f.jpeg -tagsfromfile /Source/Path/%f.png -tagsfromfile /Source/Path/%f.gif -tagsfromfile /Source/Path/%f.tif /path/to/files/

This would copy tags from the source file to the preferred location in the target file (see FAQ #9, "The tag locations change when I use -tagsfromfile to copy information"). If you wanted to copy to the exact same locations, you would have to add -All:All for each option

exiftool -tagsfromfile /Source/Path/%f.jpg -tagsfromfile /Source/Path/%f.jpeg -All:All -tagsfromfile /Source/Path/%f.png -All:All -tagsfromfile /Source/Path/%f.gif -All:All -tagsfromfile /Source/Path/%f.tif -All:All /path/to/files/

But you have to take into account that some tags may not be transferable with -All:All because the group names can't exist in the target JPEG. A lot of tags in a PNG file might belong to the PNG group and can't exist in a JPEG.

You will also get an error message for each file type that doesn't exist. You can suppress that with the -api NoWarning option.
Example
C:\>exiftool -P -overwrite_original -TagsFromFile Y:\!temp\x\y\a\%f.jpg -Description -TagsFromFile Y:\!temp\x\y\a\%f.tif -Description Y:\!temp\x\y\b
Warning: Error opening file - Y:\!temp\x\y\a\2024-07-01-12-00-00.tif
    1 directories scanned
    1 image files updated

C:\>exiftool -P -overwrite_original -api NoWarning="Error opening file" -TagsFromFile Y:\!temp\x\y\a\%f.jpg -Description -TagsFromFile Y:\!temp\x\y\a\%f.tif -Description Y:\!temp\x\y\b
    1 directories scanned
    1 image files updated
"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

Martin Z

Ah OK, thanks - that's seems do-able.

I was hoping I could maybe use a wildcard, but at the end of the day, I'm not using that many formats so copy + pasting the -tagsfromfile for each filetype is fine.

Quote from: StarGeek on October 03, 2024, 10:55:15 AMYou will also get an error message for each file type that doesn't exist. You can suppress that with the -api NoWarning option.

Ah cool, if you hadn't of mentioned this, that would've been my assumption (and so follow-up question) so thanks for covering this off. I'd quite like to keep warnings on, except the file not found ones - so from reading the page you kindly linked to, I'm thinking I can do something like... -api NoWarning "^Error opening file"

CURRENT command...

EXIFtool -TagsFromFile %tagSource%\%%f. -sep ";" -All:All -overwrite_original -m
      "-FileCreateDate<FileCreateDate" "-FileModifyDate<FileModifyDate"
      -progress:"Writing metadata: %%p%%  [%%f]" %output% >NUL

UPDATED command...

EXIFtool -api NoWarning "^Error opening file" <-- Must be first parameter I believe?
      -TagsFromFile %tagSource%\%%f.jpg -TagsFromFile %tagSource%\%%f.jpeg
      -TagsFromFile %tagSource%\%%f.png -TagsFromFile %tagSource%\%%f.gif
      -TagsFromFile %tagSource%\%%f.webp -sep ";" -All:All -overwrite_original -m
      "-FileCreateDate<FileCreateDate" "-FileModifyDate<FileModifyDate"
      -progress:"Writing metadata: %%p%%  [%%f]" %output% >NUL

Is that right?

StarGeek

See the second command in my example for the NoWarning formatting.

And if you want to use -All:All, then you need to place it after every -TagsFromFile option.
-TagsFromFile %tagSource%\%%f.jpg -All:All -TagsFromFile %tagSource%\%%f.jpeg -All:All
-TagsFromFile %tagSource%\%%f.png -All:All -TagsFromFile %tagSource%\%%f.gif -All:All
-TagsFromFile %tagSource%\%%f.webp -All:All

The reason for that is because otherwise exiftool couldn't copy different tags from different files, i.e. Description file %f.jpg, City from %f.png, etc.
"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

Martin Z

D'oh, sorry had a brain fart and didn't clock that you had actually done that already.

That's great, thanks!