I have a list of PDF in a folder in which I need to remove the sequence number and the trailing space from each of the filenames. Example.
1 Account01.pdf
2 Account05.pdf
10 Account30.pdf
I want the end result to be:
Account01.pdf
Account05.pdf
Account30.pdf
Any help would be appreciated!
Remove Sequence Nbr From Filename
Moderator: DosItHelp
Re: Remove Sequence Nbr From Filename
Try this (untested) and remove the echo keyword if it looks right on the screen.
Make sure that only the files you want renamed are in the current folder.
Make sure that only the files you want renamed are in the current folder.
Code: Select all
@echo off
for /f "tokens=1,*" %%a in ('dir /b *.pdf') do echo ren "%%a %%b" "%%b"
Re: Remove Sequence Nbr From Filename
Code: Select all
@echo off
for /f "delims=" %%i in ('dir /a-d /b *pdf^|findstr /rbc:"[0-9][0-9]* "') do (
for /f "tokens=1*" %%j in ("%%i") do ECHO ren "%%i" "%%k"
)
PAUSE
... to protect you from errors if there is more than one space between.
Also remove ECHO and PAUSE if it seems to work.
Regards
aGerman
Re: Remove Sequence Nbr From Filename
foxidrive,
It worked! You're the one! Thanks very much!
It worked! You're the one! Thanks very much!
Re: Remove Sequence Nbr From Filename
aGerman,
thanks for your response too! It will pay to have extra protection if there are more spaces!
thanks for your response too! It will pay to have extra protection if there are more spaces!
Re: Remove Sequence Nbr From Filename
Yeah, it also checks whether the file name begins with a numeric expression + space. In case you would run it twice already renamed files are untouched.
Regards
aGerman
Regards
aGerman