-if "$FileName =~ '_1.'" Does not see period

Started by dwlott, September 22, 2023, 07:11:25 PM

Previous topic - Next topic

dwlott

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"




StarGeek

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
* 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).

dwlott

" The dot . has a special meaning in regex.  It matches any single character. "
That is very helpful.  Thank you StarGeek. 

StarGeek

Oops, just copy/pasted your command and didn't notice.  The not has to be inside the quotes

-if "not $FileName =~ '_1\.'"
* 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).