I have a bunch of files that all end the same way and I want to remove the common suffix. Ex: “One (2025).txt” “Two (2025).jpg” to become “One.txt” and “Two.jpg”.
I intend to run this as a batch file on a main folder and all subdirectories.
The fix so far is not case-sensitive, so it breaks down when there is a mismatch.
I’ve found a two stage process to do this: Rename the files to just the open parentheses
forfiles /S /M "* (* /C "cmd /c ren @file *(.*"
That gives “One (.txt” and “Two (.jpg”
Then I can go through each possible letter or number combination to remove them. For example, abba (.txt would be fixed with
forfiles /S /M "*a (.* /C "cmd /c ren @file *a.*"
The issue is that it’s case sensitive, so if the file was 2ABBA (.txt it becomes 2ABBA (.txta
I can modify the forfiles command to be case sensitive
`forfiles /S /M “a (.” |findstr /c:”a (.”
Would show “abba (.txt” in the output but not 2ABBA (.txt”
I can’t figure out how to combine these pieces to get it to work
forfiles /S /M "*a (.*" |findstr /c:"a (." /C "cmd /c ren @file *(.*"
says FINDSTR: /C ignored
Adding “^” as an escape character causes other changes but not success.
user26849973 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.