copy image file to a new directory if they fulfill certain criteria

Started by Jona, March 20, 2021, 03:38:55 PM

Previous topic - Next topic

Jona

Hello,
thanks for creating this tool.

I am trying to copy image files in a new directory only if they fulfill certain criteria ex. a word in the IPTC keywords.
I tried:


                 > exiftool -if '$keywords =~ /Home_Paris/i' -o  '-filename<Paris/$filename' -ext jpg *


the output is

Error: '-filename<Paris/$filename' already exists - DJI_0027.JPG
Error: '-filename<Paris/$filename' already exists - DJI_0028.JPG
Error: '-filename<Paris/$filename' already exists - DJI_0029.JPG
1 directories created
0 image files updated
1 image files copied
3 files weren't updated due to errors


I expected 4 files to be copied and not one only. the result is that a directory is created with name : '-filename<Paris/'. In this directory I have a file named $filename containing a copy of my first image.

I tried the following command to for a comparison :

                > exiftool -if '$keywords =~ /Home_Paris/i'   '-filename<Paris/$filename' -ext jpg *.   (remove the option  -o)


the output is

Warning: [minor] Possibly incorrect maker notes offsets (fix by 1783?) - DJI_0007.JPG
Warning: [minor] Possibly incorrect maker notes offsets (fix by 1783?) - DJI_0027.JPG
Warning: [minor] Possibly incorrect maker notes offsets (fix by 1783?) - DJI_0028.JPG
Warning: [minor] Possibly incorrect maker notes offsets (fix by 1783?) - DJI_0029.JPG
    1 directories created
    4 image files updated


this moved my 4 images, the expected result.

can you help me, what do I do wrong in the command to copy the files.

thank you

StarGeek

The -o (-out) option requires a second parameter.  Normally this would be a directory, file name or format string, depending upon the usage.  But since you want to use the Filename pseudo tag, that will override the location that would normally be set with the -o.  But the -o still requires that second paramater, even though it will be ignored.  In this situation, it's common to use a dot . as a placeholder.

So try
exiftool -if '$keywords =~ /Home_Paris/i' -o . '-filename<Paris/$filename' -ext jpg *

See the notes section of Writing "FileName" and "Directory" tags for more details.

* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Jona

thank you was struggling with this one.
it works

for my elevation.
would you have used an other way more efficient to do the same thing?

BR.
Alexandre

Phil Harvey

Two points:

1. Why did you use * instead of . ?

2. Why are you writing FileName instead of Directory?  You should only do this if the JPG files are in directories inside the current directory and you don't want to process further subdirectories.  (To process all subdirectories, just add -r to the command below.)

I would have done this:

exiftool -if '$keywords =~ /Home_Paris/i' -o . '-directory=Paris' -ext jpg .

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

Jona

thank you
I will use both recommendations.

1. Because I am used to the * for all. But you are right the . for current directory is more logical.

2. Because I learn.

The new command line will be in my personal cheatsheet

Thank you for your time
Alexandre

StarGeek

Quote from: Jona on March 21, 2021, 11:00:51 AM
1. Because I am used to the * for all. But you are right the . for current directory is more logical.

This becomes especially important if you need to use the -r (-recurse) option.  See Common Mistake #2

QuoteThe new command line will be in my personal cheatsheet

Just make sure if you are using a word processor for your cheat sheet, that you double check the quotes.  Word processors/google docs will "help" you by changing normal quotes
" '
into fancy quotes.
"" ''
The latter will not work on the command line.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Jona

good points.
I use a simple text editor not looking pretty but does the trick for my old fashion style.