ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: philbond87 on May 01, 2020, 02:47:18 PM

Title: Wildcard in filename question
Post by: philbond87 on May 01, 2020, 02:47:18 PM
I'm trying to run a  -tagsFromFile command on a folder of files however I only want the operation to affect filenames in the folder that contain a specific string.

Is that possible and, if so, how would I structure the command?

Thanks,
Phil
Title: Re: Wildcard in filename question
Post by: StarGeek on May 01, 2020, 02:58:32 PM
As long as you aren't recursing into subdirectories, you can just use the asterisk *.  As an example
exiftool -TagsFromFile /path/to/source/%f.%d -DateTimeOriginal /path/to/target/file*SpecificString*

If you need to affect all files with the specific string in all sub-directories, it's a bit more complex as you can't use the asterisk wildcard (see -r (recurse) option (https://exiftool.org/exiftool_pod.html#r-.--recurse) and Common Mistake #2 (https://exiftool.org/mistakes.html#M2)).  It will require the -if option (https://exiftool.org/exiftool_pod.html#if-NUM-EXPR) and some sort of pattern matching, usually RegEx.  You use a directory as the target path.  To process the current directory, use a dot .
exiftool -if "$Filename=~/SpecificString/i" -TagsFromFile /path/to/source/%f.%d -DateTimeOriginal /path/to/target/files/

If you're on Mac/Linux, swap the double/single quotes.
Title: Re: Wildcard in filename question
Post by: philbond87 on May 01, 2020, 03:55:33 PM
Very helpful, thanks for the tips!
Title: Re: Wildcard in filename question
Post by: philbond87 on May 01, 2020, 04:28:54 PM
Ok, of course that worked.

Is there a way to include a conditional?
What I'd ultimately like to do is – in addition to performing the operation on a file with a particular string in the file name – I'd like to ignore a handful of file types (particular extensions).

Thanks again
Title: Re: Wildcard in filename question
Post by: StarGeek on May 01, 2020, 05:11:54 PM
Just add the condition as show above.  Order doesn't matter for most options, you just can't split options that need an additional argument like -TagsFromFile or -if.  For ease you can just drop it onto the end.

To ignore a filetype, use the -ext (extension) option (https://exiftool.org/exiftool_pod.html#ext-EXT---ext-EXT--extension).  Use two dashes to ignore a file type e.g. --ext avi to ignore avi files.  Though avi files would normally be skipped as they are not editable by exiftool.