Rename/Copy Image and create sidecar

Started by berliner_ffm, May 17, 2020, 05:36:34 PM

Previous topic - Next topic

berliner_ffm

I am writing a script that allows the user to give a renaming scheme and that should then rename (and copy if wanted) imagefiles from a filelist and in the same process create XMP-files for all files in the filelist. Of course the xmp-files should carry the same name as the renamed image except for the extension.

The only way i figured out might work was with an arg-file, that will first create the xmp in the new location and then rename/copy the original.

Here is what I came up with:

ArgFile:

-tagsfromfile
angkor-050773.dng
-filename<${CreateDate}_%-6f_test.xmp
-all:all<xmp:all
-execute
angkor-050773.dng
-filename<${CreateDate}_%-6f_test.%e
-preservedfilename<filename
-execute

("Test" was used as a dummy Sessioname, which the user will provide at  the beginning of my script-execution)

Command:
exiftool -@ exifargfile.csv -common_args -d %Y%m%d -o dummy

The good thing is, the script created 2 files, an xmp and a copy of the image. The copy of the image ok, but for the xmp "%-6f" is not recognized. It looks like the filename shortcuts do not refer to the tagsfromfile argument. Additionally the scipt gives a message "nothing to write" at the end.

So my two questions are:
-how can I create an xmp-file for an image that I will rename and where my script does not know the new filename yet (only the structure)?
-What causes the "nothing to write" message?

In addition: would there be a way to do it in one command, so that the files only have to be opened once? Or is there a way to export the new filenames into a file?

Thanks for your help!

berliner_ffm

#1
ok, i managed to get one step further, by creating the sidecar first and then copy it (not nice since it would require to write on a memory card, but it would work).
So my ARGFILE is now:

-tagsfromfile
@
-srcfile
%d%f.xmp
angkor-050773.dng
-all:all<xmp:all
-execute
angkor-050773.dng
angkor-050773.xmp
-filename<%d${CreateDate}_%-6f_test.%e
-preservedfilename<filename
-o
dummy
-d
%Y%m%d
-execute


The command is reduced to:
exiftool -@ exifargfile.csv

Now I am getting to following error msg:

exiftool -@ exifargfile2.csv
    1 image files updated
Warning: Error opening file - dummy
Error: File not found - dummy
    2 image files created
    0 image files updated
    1 files weren't updated due to errors


Hope you can help with the error messages or provide a more efficent way.
Thanks

Phil Harvey

Here is one way to copy the files from the memory card while renaming and creating the sidecar files:

exiftool -@ my.args -common_args -d %Y%m%d DIR

with this my.args file:

-o
outdir/%f.xmp
-execute
-filename<${CreateDate}_%-6f_test.xmp
-srcfile
outdir/%f.xmp
-execute
-directory=outdir
-o
.
-filename<${CreateDate}_%-6f_test.%e
-preservedfilename<filename


The first command creates the xmp sidecar file in "outdir".  The second command renames the XMP file, then the third command copies the image file to "outdir" and renames it.

But if "DIR" is on the memory card then this is probably the slowest possible way to do this, since the image is read 3 times from the memory card.  Instead, it would be better to copy all the files off the card to a temporary directory on the hard disk, then run the command on this directory (but remove the "-o ." from the last command so the file is moved instead of being copied again):

exiftool -@ my.args -common_args -d %Y%m%d

-o
tmpdir/%f.%e
DIR
-execute
-o
outdir/%f.xmp
tmpdir
-execute
-filename<${CreateDate}_%-6f_test.xmp
-srcfile
outdir/%f.xmp
tmpdir
-execute
-directory=outdir
-filename<${CreateDate}_%-6f_test.%e
-preservedfilename<filename
tmpdir


..but there may be a more efficient way to do this.  I don't have time to think about this too much right now.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

berliner_ffm

Thanks Phil, copying to a temp-folder simplied it very much. Only I do the copy into the temp-folder with the native powershell command
.
My final argfile is now:

-TagsFromFile
@
-srcfile
%d%f.xmp
C:\Users\jens\documents\50_exiftool\tmp\
-alldates<alldates
-datecreated<datecreated
-all:all<xmp:all
-preservedFileName<FileName
-execute
C:\Users\jens\documents\50_exiftool\tmp\
-ext
xmp
-filename<C:\Users\jens\Pictures\00_unfinished\_currentWork\${DateCreated}_odf_%-7f%+2c.%e
-execute
C:\Users\jens\documents\50_exiftool\tmp\
-filename<C:\Users\jens\Pictures\00_unfinished\_currentWork\${DateCreated}_odf_%-7f%+2c.%e
-preservedFileName<FileName
-execute


So step 1 (creating xmp) and step 2 (moving xmp to final location) work perfectly.
step 3 however has a problem. It will create a new file with the correct new filename in the destination folder. However the file will not be moved from tmp but copied instead, so that the original is still in the temp-folder after the process finishes. No -o-Option is used.
I don't understand why it works with the xmp-files but not with the images.
You have any idea?

Phil Harvey

Quote from: berliner_ffm on May 19, 2020, 04:11:05 PM
step 3 however has a problem. It will create a new file with the correct new filename in the destination folder. However the file will not be moved from tmp but copied instead, so that the original is still in the temp-folder after the process finishes. No -o-Option is used.
I don't understand why it works with the xmp-files but not with the images.

Right.  You are actually modifying the file by writing PreservedFileName, so you need to add -overwrite_original to keep ExifTool from preserving the original file.

BTW, you don't need a -execute at the end of the argfile.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).