Copy images according to search criteria

Started by Vlermuis, June 29, 2018, 10:34:43 AM

Previous topic - Next topic

Vlermuis

Hi All,

Apologies if this question has been asked before, I did not see it anywhere.

I am struggling to figure out what the ExifTool  command or code would be for when you want to check through a folder with millions of photos and select only certain photos with a specific tag (tags made in windows live gallery) but only the photos of say 2016.

In this folder I have, there are numerous folders with photos from 2011 till 2018. I would only like to extract and copy the images taken in 2016 of leopards (all these images have been tagged "Leopard" using windows live gallery and therefore is in the image metadata) and then copy it to a new folder on my computer. I am not sure if this is possible as I can't wrap my head around the syntax.

Thank you for your time,

Best Wishes,
Vlermuis

StarGeek

You'll have to take the time to double check the metadata of your photos (see FAQ #2) but the command would probably be something like this:

exiftool -o . "-Directory=C:\NewDirectory" -if "$subject=~/Leopard/i and $DateTimeOriginal=~/^2016/" C:\SourceDirectory

-o . indicates that the command will make a copy of the file.  The dot would normally make the copy in the current directory but that is overridden by the "-Directory=C:\NewDirectory" option, which will copy to the "C:\NewDirectory" (change that to the directory you want to copy to).

The -if option check the tags using two Regular Expressions (RegEx).  First, it checks for the occurrence of "Leopard" in the Subject tag.  I'm only guessing that Windows Live Gallery writes to that tag, so you'll have to double check.  If not there, then also check Keywords and XPSubject.  The "i" after the slash indicates that the check is case insensitive.  One thing to watch out for with this is that it may match other keywords that contain "Leopard".  For example, it would also match the keyword of "Leopard Shark".  If that's the situation, a more complex -if statement is required.

The second part checks the most common timestamp for images to see if the timestamp starts with 2016.  If your images are from sources other than a camera, then you'll have to double check to see if they have a proper time stamp, which might be in a different tag.
"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

Vlermuis

Hi,

Thank you very much for the quick reply of earlier. I've been trying you're code in my terminal since you've sent it. I've also reread the ExifTool Application Documentation, Writing "FileName" and "Directory" tags document, and some of the other help files. I just can't seem to get this right. Sorry to be a nuisance .

If I run this line, the images copy fine, but it copies everything (this is luckily only a sample set):

exiftool -o . "-Directory=/Users/philipfaure/Desktop/test" /Users/philipfaure/Desktop/a

So, I know this is right.

If I add the conditional if statements for the species tag or year, such as below:
exiftool -o . "-Directory=/Users/philipfaure/Desktop/test" -if "$Subject=~/Leopard/i" /Users/philipfaure/Desktop/a

or:

exiftool -o . "-Directory=/Users/philipfaure/Desktop/test" -if "$Subject=~/Leopard/i and $DateTimeOriginal=~/^2016/" /Users/philipfaure/Desktop/a

Then I get the following output for both:

1 directories scanned
15 files failed condition
0 image files read


I have also swapped out $Subject for $XPKeywords, and $LastKeywordXMP as these also contain the "Leopard" tag.

I am running these commands from the terminal in a MacBook Pro High Sierra.

Thank you for your time, much appreciated!

Best Wishes,
Vlermuis

StarGeek

Quote from: Vlermuis on June 29, 2018, 03:13:54 PM
I am running these commands from the terminal in a MacBook Pro High Sierra.

Ah, since you mentioned Windows Live Gallery I assumed you were on Windows.  On a Mac/Linux, you have to swap double quotes for single quotes to avoid the shell from thinking that anything starting with a dollar sign is a shell variable.

So try:
exiftool -o . '-Directory=/Users/philipfaure/Desktop/test' -if '$Subject=~/Leopard/i and $DateTimeOriginal=~/^2016/' /Users/philipfaure/Desktop
"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

Vlermuis

IT WORKSSS!!!!! THANK YOU SO MUCH!!
;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D

I hope you have a great weekend! And thanks again for the immensely quick responses!

Best Wishes,
Vlermuis


Vlermuis

Hi......

I am back...unfortunately.. :-[

So the code works perfectly but there is only one problem, it doesn't copy all the images if some of them are named the same.. e.g. if two images are both named IMG_0001.JPG but are in different folders.

I have added the -r argument in the line of code so that it can recurse through all folders:

exiftool -o . '-Directory=/Users/philipfaure/Desktop/test' -if '$Subject=~/Leopard/i and $DateTimeOriginal=~/^2016/' /Users/philipfaure/Desktop/test1

Is there a way to either keep the subfolder structure and copy all of that over or otherwise rename the image by adding a number to the filename?

Thank you,

Best Wishes

StarGeek

The easiest I think would be to change the file name and add the %c variable (see the -w option).  It could be possible to keep the directory structure, but that's more complicated.

Try this
exiftool -o . '-Filename=/Users/philipfaure/Desktop/test/%f%-c%E' -if '$Subject=~/Leopard/i and $DateTimeOriginal=~/^2016/' /Users/philipfaure/Desktop/test1

In this case, if IMG_0001.JPG already exists, it will use IMG_0001-1.JPG
"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

Vlermuis

Thank you so much for all your help!! I really appreciate it!

I changed your code just a little to be able to recurse through all the folders (added the "-r" argument).

exiftool -r -o . '-Filename=/Users/philipfaure/Desktop/test/%f%-c%E' -if '$Subject=~/Leopard/i and $DateTimeOriginal=~/^2016/' /Users/philipfaure/Desktop/a

Best Wishes