Here's some quick untested example code, which should rename, YYYYYYYYYY(X).txt
to (X).txt
, YYYYYYYYYY(XX).txt
to (XX).txt
, YYYYYYYYYY(XXX).txt
to (XXX).txt
, and YYYYYYYYYY(XXXX).txt
to (XXXX).txt
, subject to matching names not already existing, and which is exactly what your question asks.
@For %%G In ("C:\Users\Gary\Documents\?*(*).txt") Do @(
Set "}=%%~nG" & SetLocal EnableDelayedExpansion
Ren "%%G" "(!}:*(=!%%~xG" & EndLocal)
Here's some additional untested example code, which should rename, YYYYYYYYYY(X).txt
to X.txt
, YYYYYYYYYY(XX).txt
to XX.txt
, YYYYYYYYYY(XXX).txt
to XXX.txt
, and YYYYYYYYYY(XXXX).txt
to XXXX.txt
, subject to matching names not already existing.
For %%G In ("C:\Users\Gary\Documents\*(*).txt") Do (
Set "f=%%~nG"
SetLocal EnableDelayedExpansion
Set "n=!f:*(=!"
Ren "%%G" "!n:~,-1!%%~xG"
EndLocal
)