ExifTool to search for files with given tag value

Started by bflo2000, February 22, 2023, 01:43:31 PM

Previous topic - Next topic

bflo2000

I've tried the below to search a folder of images for the Color Mode "Grayscale"

exiftool -ColorMode -if "-$Grayscale" H:\ > gray.csv

The file is created, but the output says 0 image files read

Any ideas if this is possible?

StarGeek

The command as written is looking for the existence of  a tag with the name "Grayscale", which doesn't exist (at least I don't think it does).

You have to compare the tag you're searching for to the value that is in the file.  The version looks for a value of exactly "Grayscale", case sensitive.
exiftool -if "$ColorMode eq 'Grayscale' " -ColorMode H:\ >gray.csv

Alternatively, you could use regex and do a case insensitive comparison
exiftool -if "$ColorMode=~/Grayscale/i" -ColorMode H:\ >gray.csv

These commands would be for using Windows CMD.  If you're using PowerShell (or Mac/Linux), then swap the double/single quotes.

"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

Phil Harvey

Additionally, you might want to add the -csv option if you are looking for a CSV-formatted output.

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

bflo2000

#3
I tried both examples, and added the -csv, but I am getting the following that is not finding Grayscale

exiftool -csv -r -if "$ColorMode eq 'Grayscale' " -ColorMode H:\ >gray.csv
exiftool -csv -r -if "$ColorMode=~/Grayscale/i" -ColorMode H:\ >gray.csv

1 files failed condition
1 image files read

Here is a link to the output when dropping a Grayscale file onto exiftool (showing the Grayscale output)

https://nimb.ws/TWr5Pe

Thanks

StarGeek

It works correctly here in CMD.  Did you see the last line of my post?
C:\>exiftool -csv -r -if "$ColorMode eq 'Grayscale' " -ColorMode y:\!temp\Test4.jpg
SourceFile,ColorMode
y:/!temp/Test4.jpg,Grayscale

C:\>exiftool -csv -r -if "$ColorMode=~/Grayscale/i" -ColorMode y:\!temp\Test4.jpg
SourceFile,ColorMode
y:/!temp/Test4.jpg,Grayscale
"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

bflo2000

I'm not sure what I was doing wrong but I have it working now with the below.  I think it was something to do with the csv export,

exiftool -csv -r -if "$ColorMode eq 'Grayscale' " -ColorMode -ext jpg H:\ > colormode2.csv

Thank you both for your assistance.  This is very useful because I am going through folders with over 500K images.