In my example, I have 30 or so .pdfs named "DR DES LSEC01.pdf", "DR DES LSEC02.pdf" and so on.. up to "DR DES LSEC32.pdf". I want to keep the existing numerals (i.e. 01, 02, 03 etc.), and then add on a pre-fix (in my example, the pre-fix is "DS2019.000450-CD-SM-03").
I have created a looped batch file to loop through each .pdf and rename each by copying (I have also tried to use the rename function to no avail).
Currently, if I run the code, it either says: 1) Syntax is incorrect (if I use the 'ren' function); or 2) The system cannot find the file specified (if I use the copy function)
setlocal EnableDelayedExpansion
set A="DR DES LSEC"
set prefix=DS2019.000450-CD-SM-03
For %%a in (%A%) do (
For %%f in ( %%a*.pdf ) do (
set oldfilename=%%~nf
set oldname=!oldfilename:~-2!
set newname=!prefix!-!oldname!
echo %%f
echo !newname!
copy y/ %%f !newname!.pdf
)
)
pause
Can you try out below snippet
setlocal EnableDelayedExpansion
set A="DR DES LSEC"
set prefix=DS2019.000450-CD-SM-03
For %%a in (%A%) do (
For %%f in ( %%a*.pdf ) do (
set oldfilename=%%~nf
set oldname=!oldfilename:~-2!
set newname=!prefix!-!oldname!
echo %%~nf
echo !newname!
copy y/ %%~nf !newname!.pdf
)
)
pause