Recursive only IF folder doesn't contain specific words

Started by Chris S, March 12, 2023, 01:00:13 PM

Previous topic - Next topic

Chris S

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]

Phil Harvey

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


Chris S

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)

Phil Harvey

The "old" matches this character sequence in "folder".  If you want whole words, do this:

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

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

Chris S

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!