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"
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
" The dot . has a special meaning in regex. It matches any single character. "
That is very helpful. Thank you StarGeek.
Oops, just copy/pasted your command and didn't notice. The not has to be inside the quotes
-if "not $FileName =~ '_1\.'"