Specifying "any extension but this one" to -tagsfromfile

Started by akrabat, August 26, 2019, 07:41:25 AM

Previous topic - Next topic

akrabat

I have many directories full of RAW files from various manufacturers with associated XMP files that share the same filename as the RAW file. Due to the number of photos and directories involved, I'm trying to put this into a shell script.


I'm trying to move all the files into year/month/day directories and rename the file at the same time based on the DateTimeOriginal.

From reading other threads here, I realise that I need to move the XMP file separately to the RAW file as I can then use --tagsfromfile to use the RAW file's DateTimeOriginal.

I can do this using:


exiftool -tagsfromfile %d%f.NEF "-filename<DateTimeOriginal" -d "%Y/%m/%d/RKA_%Y%m%d-%H%M%S%%-c.%%e" -ext xmp .


But this only does the NEF files. How can I specify multiple extensions in --tagsfromfile? or even better, how do I say "any extension other than XMP"?

I tried -tagsfromfile %d/%f.!XMP & -tagsfromfile %d/%f.[^XMP], but neither of those work, so I'm guessing  that the solution is a little more subtle.


Another idea I had was to use a separate ExifTool command for each extension in the shellscript, but exiftool displays a warning along the lines of Warning: Error opening file - ./IMG_1234.CR2 which clogs up the command line very quickly! Is there any way to turn off the warning but still display the summary information?

I could also be approaching this problem from completely the wrong direction, so is there another way to do this?

Thanks.

Phil Harvey

You can repeat the -tagsFromFile option for each possible extension.  For example:

exiftool -tagsfromfile %d%f.NEF "-filename<DateTimeOriginal" -tagsfromfile %d%f.CR2 "-filename<DateTimeOriginal" -d "%Y/%m/%d/RKA_%Y%m%d-%H%M%S%%-c.%%e" -ext xmp .

You will get warnings about the files it doesn't find, but this should work.

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

Hayo Baan

Quote from: Phil Harvey on August 26, 2019, 08:10:20 AM
You can repeat the -tagsFromFile option for each possible extension.  For example:

exiftool -tagsfromfile %d%f.NEF "-filename<DateTimeOriginal" -tagsfromfile %d%f.CR2 "-filename<DateTimeOriginal" -d "%Y/%m/%d/RKA_%Y%m%d-%H%M%S%%-c.%%e" -ext xmp .

You will get warnings about the files it doesn't find, but this should work.

Ah, that should do it, indeed! I was working on a more generic way, but ran into the problem of %-c not being evaluated yet when I need it. Without that, you could try something like this too:

exiftool '-filename<${DateTimeOriginal; my $x = $self->GetValue("FileName"); $x =~ s/\.[^.]*$/.xmp/; if (-f $x) { my $nx = $_; $nx =~ s/\.[^.]*$/.xmp/; use File::Basename qw(dirname); use File::Path qw(make_path); make_path(dirname($nx)); use File::Copy qw(move); move($x, $nx); }; }' -d '%Y/%m/%d/RKA_%Y%m%d-%H%M%S%.%%e' -if '$filename !~ /\.xmp/i' .

Note: this is for Mac/Linux, for Windows, switch the single and double quotes. The code looks a bit complex but I had to ensure the new directory existed before the move.
Hayo Baan – Photography
Web: www.hayobaan.nl