Copying Metadata from a file to a new file with a different name and location

Started by cameronsamson, October 30, 2018, 04:05:13 PM

Previous topic - Next topic

cameronsamson

I've tried a few times and ways with no success,

I want to copy the metadata from images in a directory to a sub-directory folder where I have done raster calculations on those images and they have lost the metadata in the process. The images have also been assigned a Corrected to the beginning of the image name. I want to do it all in a batch file and therefore I currently have

OLD image names
IMG_180810_145708_0000_GRE.TIF
IMG_180810_145708_0000_RED.TIF
IMG_180810_145708_0000_NIR.TIF
IMG_180810_145708_0000_REG.TIF

New images
CorrectedIMG_180810_145708_0000_GRE.TIF
CorrectedIMG_180810_145708_0000_RED.TIF
CorrectedIMG_180810_145708_0000_NIR.TIF
CorrectedIMG_180810_145708_0000_REG.TIF

Current batch file is set up as such

    @echo off
    echo %CD%
    set directory=%CD%

::All my raster calculations that are done on my images and exported to a sub-directory folder called \RCalibration\Images_Corrected\

::Trial code

    exiftool.exe -tagsfromFile @ %directory%/%f.TIF -ext TIF %directory%\RCalibration\Images_Corrected

but this does not work or writes all the metadata from one file to every file which is not useful. is there a way to transfer the metadata to the new images even if they have a new Corrected name appended to them at the begining.

I've had success when I use the individual names but would like to to them all at once, and as a batch as its all automated and I have lots of images.

exiftool.exe -tagsfromFile @ %directory%/IMG_180810_145708_0000_GRE.TIF -ext TIF %directory%\RCalibration\Images_Corrected\CorrectedIMG_180810_145708_0000_GRE.TIF

StarGeek

Just to clarify, the original images are in %directory% and the new images are in %directory%\RCalibration\Images_Corrected

You're close, but the problem is that the file names are different.  The %f variable is the target filename, but your source filename doesn't have the Corrected prefix.  So that will have to be modified.  You can see the options to modify %f under the -w (textout) option.  In this case, you want to ignore the first 9 characters, so that means you want to use %.9f as the filename variable.

So try
exiftool -ext TIF -TagsFromFile %directory%/%.9f.tif" %directory%/RCalibration/Images_Corrected

Example output, where original file has a Description and the corrected file doesn't:
C:\>exiftool -ext tif -g1 -a -s -r -Description Y:\!temp\mm
======== Y:/!temp/mm/IMG_180810_145708_0000_GRE.tif
---- XMP-dc ----
Description                     : test
======== Y:/!temp/mm/RCalibration/Images_Corrected/CorrectedIMG_180810_145708_0000_GRE.tif
    3 directories scanned
    2 image files read

C:\>exiftool -P -overwrite_original -progress -ext TIF -TagsFromFile Y:/!temp/mm/%.9f.tif Y:/!temp/mm/RCalibration/Images_Corrected
======== Y:/!temp/mm/RCalibration/Images_Corrected/CorrectedIMG_180810_145708_0000_GRE.tif [1/1]
    1 directories scanned
    1 image files updated

C:\>exiftool -ext tif -g1 -a -s -r -Description Y:\!temp\mm
======== Y:/!temp/mm/IMG_180810_145708_0000_GRE.tif
---- XMP-dc ----
Description                     : test
======== Y:/!temp/mm/RCalibration/Images_Corrected/CorrectedIMG_180810_145708_0000_GRE.tif
---- XMP-dc ----
Description                     : test
    3 directories scanned
    2 image files read
"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

cameronsamson

Thank you! That works well in the command line but doesn't work in my batch file. Returns an error with the %.9f with no files detected. My guess is that its %.9f isn't happy in the batch file. But it definitely works well in regular command prompt.  :)

StarGeek

"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