ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: dwlott on September 22, 2023, 07:11:25 PM

Title: -if "$FileName =~ '_1.'" Does not see period
Post by: dwlott on September 22, 2023, 07:11:25 PM
Greetings to all.  Perhaps someone can help.

I'm trying to get rid of a duplicated files by a conditional copy.  The duplicates have a count string appended to the end of the file name, before the extension. Example: filename_10092.jpg and filename_10092_1.jpg. I can't use just the '_1', the statement needs the period also.
 
This performs the function if the filename does not contains a '_1' in its string.
-if not "$FileName =~ '_1'"

This appears to perform the same function as above, and appears to ignore the .
-if not "$FileName =~ '_1.'"

The full command line that I am using:
e:\exiftool\exiftool -If "not $FileName =~ '_1.'" -o . "-Directory=e:\myTargetFolder" "E:\mySourceFolder"



Title: Re: -if "$FileName =~ '_1.'" Does not see period
Post by: StarGeek on September 22, 2023, 07:30:13 PM
The dot . has a special meaning in regex.  It matches any single character.  So as long as there is any character after the "_1", it will always match.

You'll have to escape the dot with a backslash
-if not "$FileName =~ '_1\.'"

Other characters to watch for (a copy/paste from my clipboard)
Regex special characters . ^ $ * + - ? ( ) [ ] { } \ | — /

Hmmm... I think an ndash (or mdash) snuck in there near the end
Title: Re: -if "$FileName =~ '_1.'" Does not see period
Post by: dwlott on September 23, 2023, 05:49:59 PM
" The dot . has a special meaning in regex.  It matches any single character. "
That is very helpful.  Thank you StarGeek. 
Title: Re: -if "$FileName =~ '_1.'" Does not see period
Post by: StarGeek on September 23, 2023, 06:10:26 PM
Oops, just copy/pasted your command and didn't notice.  The not has to be inside the quotes

-if "not $FileName =~ '_1\.'"