I am trying to move images based on the contents of the Subject tag, with the code provided below.
All images that contain a 1: within the tag are moved into a subdirectory named according to the species name following the 1:. However, images that do not have the 1: in their tag are not being moved to a 'Empty' directory, but are moved into the image_sorted directory.
exiftool -m -r '-Filename=../Data/image_sorted/Empty/%f%+c%E' '-Filename<../Data/image_sorted/${Subject;$_=undef if not s/.*(?:^|, )1: (.*?)(,|$).*/$1/}/%f%+c%E' ../Data/image_raw
I am using relative pathways, does this have an influence?
Any ideas?
The way you have it, the images that don't match are being moved into a "../Data/image_sorted/Empty" directory. Did you want just "../Data/Empty" instead?
- Phil
Thanks for the quick reply.
No I would like them to be moved into a subdirectory within the 'image_sorted' directory. However, currently the images are being moved into "../Data/image_sorted", and not into "../Data/image_sorted/Empty"
Therefore, I currently have to use the following line of code:
mv ../Data/image_sorted/*.jpg ../Data/image_sorted/Empty
Ah. I see.
The problem is the -m option, which ignores missing tag values and replaces them with an empty string.
Remove the -m and it should work for you.
Buried deep within the documentation:
the -m option may be used to ignore minor warnings and leave
the missing values empty.
- Phil
Original post (https://stackoverflow.com/questions/50526638/inverse-matching-with-exiftool) on StackOverflow.
Glad to see the problem get fixed, philipp_hb. I didn't realize that the -m option would do that in this case. You'll get the minor error response I mentioned but it can be ignored.
Thank you both for the help!
I've instead added 2> /dev/null
at the end of the command to suppress the warning messages.
However, I've now encountered another problem, where if I add the -o tag (to copy instead of moving the images), the empty images (missing the 1:) are not being copied at all, whereas all other images are.
Again, appreciate any input!
Did you forget to give -o an argument? Use "-o ."
- Phil
That was it! Could you explain what the '.' argument is for?
Cheers,
Philipp
-o requires an argument which is a file name, directory name, or filename/directory format string. But you are overriding the output directory by specifying a directory when you set the FileName tag, so anything would do here ("." is just convenient). See Example 11 here (https://exiftool.org/filename.html#ex11).
- Phil