List Files That Contain a Certain Tag

Started by mulu, February 22, 2020, 11:29:18 AM

Previous topic - Next topic

mulu

I need to get a list of files that contains a particular tag, e.g. XMP-xmp:Label. I can do

exiftool -r -XMP-xmp:Label [directory]

This lists all files. The ones that contain the tag will list the value and the others just list the filename. So I looked into the -if statement and read the manual and some forum posts but still failed. For instance I tried

exiftool -r -if -XMP-xmp:Label [directory]

but that any many other variations doesn't give me any result.

Edit: I think what I am doing above is looking for files where the -XMP-xmp:Label tag has the value [directory]. But what I really want to do is searching for files that have the tag -XMP-xmp:Label. I don't care what the value is. And I only want to list the files that have that tag (I expect very few to have the tag so I don't want to see the files that don't have the tag).

StarGeek

From the docs on the -if option
   EXPR is a Perl-like logic expression containing tag names prefixed by $ symbols.

So try this:
exiftool -r -if "$XMP-xmp:Label" -XMP-xmp:Label <FileOrDir>
or even just
exiftool -r -if "$Label" -Label <FileOrDir>
* 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).

mulu

StarGeek

Thanks a lot for the quick reply. I ended up with

exiftool -XMP-xmp:Label -p "$filename" -r -if "$XMP-xmp:Label"

or more general

exiftool -[TagName] -p "$filename" -r -if "$[TagName]"

Note that -p "$filename" makes exiftool output the location of the file that contains the tag [TagName]. If you want to know what the value is then leave this out. It will produce two lines per file that contain [TagName], though.
Also the examples use single quotes  which didn't work for me. I had to use double quotes or "$[TagName]".

FixEUser

Thanks a lot for your example @mulu.

I was able to apply it for my recursive search for all *.mp3 music files including a Cover Picture Description (for the included APIC cover art picture).
I only wanted to output the filenames for the ones matching this condition.

exiftool -m -ID3:PictureDescription -p "$filename contains ID3PictureDescription:$ID3:PictureDescription" -r -if "$ID3:PictureDescription" *.mp3

Option -m stands for "Ignore minor errors and warnings"
This will output the following line for a mp3 file including a Picture Description:
04 - For My Baby.mp3 contains ID3PictureDescription:Test Cover Description
   12 files failed condition