ExifTool Forum

ExifTool => Newbies => Topic started by: bflo2000 on February 22, 2023, 01:43:31 PM

Title: ExifTool to search for files with given tag value
Post by: bflo2000 on February 22, 2023, 01:43:31 PM
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?
Title: Re: ExifTool to search for files with given tag value
Post by: StarGeek on February 22, 2023, 01:57:34 PM
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.

Title: Re: ExifTool to search for files with given tag value
Post by: Phil Harvey on February 22, 2023, 02:13:06 PM
Additionally, you might want to add the -csv option if you are looking for a CSV-formatted output.

- Phil
Title: Re: ExifTool to search for files with given tag value
Post by: bflo2000 on February 22, 2023, 02:34:37 PM
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
Title: Re: ExifTool to search for files with given tag value
Post by: StarGeek on February 22, 2023, 03:16:56 PM
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
Title: Re: ExifTool to search for files with given tag value
Post by: bflo2000 on February 22, 2023, 08:41:27 PM
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.