ExifTool Forum

ExifTool => Newbies => Topic started by: Chris S on March 12, 2023, 01:00:13 PM

Title: Recursive only IF folder doesn't contain specific words
Post by: Chris S on March 12, 2023, 01:00:13 PM
If I wanted to return metadata from files within a root directory recursively, but only drill down into a folder if it does not contain some variant of "Old" or "Archive" (irrelevant of upper/lowercase), is it possible to do this with a single Exiftool command? I haven't graduated to If statements with Exiftool yet, so would appreciate any help. Thank you!

exiftool -r [tags] [Dir]
Title: Re: Recursive only IF folder doesn't contain specific words
Post by: Phil Harvey on March 12, 2023, 07:51:30 PM
There is no way to do exactly what you want.  The -i option ignores directories with a specified name, but won't match a partial string in the name.

The closest I can do this this:

exiftool -if5 "$directory !~ /old|archive/i" -r DIR

which will actually scan all files in these directories but using the fast5 level for this scan, so it shouldn't be too slow.

- Phil
Title: Re: Recursive only IF folder doesn't contain specific words
Post by: Chris S on March 13, 2023, 07:26:28 PM
Perfect! Thank you!
Title: Re: Recursive only IF folder doesn't contain specific words
Post by: Chris S on June 12, 2023, 11:09:07 PM
I'm experiencing an issue with the code below in that it will not work with a directory named untitled folder.

exiftool -if5 '$directory !~ /old|archive/i' -r -Filename DIR

More specifically, if the base folder where images are contained is named untitled folder the entire condition will fail. If a subfolder is named untitled folder, the "if" condition will fail on that folder as if it were "old" or "archive". Any thoughts how to rectify?

Versions: ExifTool 12.63, MacOS 13.3.1 (a)
Title: Re: Recursive only IF folder doesn't contain specific words
Post by: Phil Harvey on June 13, 2023, 06:04:48 AM
The "old" matches this character sequence in "folder".  If you want whole words, do this:

-if5 '$directory !~ /\b(old|archive)\b/i'

- Phil
Title: Re: Recursive only IF folder doesn't contain specific words
Post by: Chris S on June 13, 2023, 12:42:52 PM
Thank you Phil. I must have been blind not to see the word old in the word Folder!

I found another workaround with some error catching since I'd like to keep the partial word match, but I appreciate the \b code suggestion for future reference!