I have a ton of PDF files in a folder. It is named in this format:
ABC - Deposit 07-05-23.pdf
I would like a batch file to replace the "- Deposit" with "TALLY" instead.
If possible, I would also like the date format to be replaced from MM/DD/YY.pdf to MM.DD.YY.pdf. So basically remove the dashes in the date to periods instead.
Thank you for the help on this.
Replace Word In Filename With Another Word
Moderator: DosItHelp
Re: Replace Word In Filename With Another Word
For reference of what I would like the result to be:
Original File Name
ABC - Deposit 07-05-23.pdf
New File Name:
ABC TALLY 07.05.23.pdf
Original File Name
ABC - Deposit 07-05-23.pdf
New File Name:
ABC TALLY 07.05.23.pdf
Re: Replace Word In Filename With Another Word
Again this is basic string substitution. Your last two forum threads covered both of what you want to do. What don't you understand?
Re: Replace Word In Filename With Another Word
Code: Select all
@echo off
cd /d "%~dp0"
for /f "delims=" %%i in ('dir /b /s /a-d *-*.pdf') do (
set "OldFile=%%i"
set "OldName=%%~nxi"
setlocal enabledelayedexpansion
set NewName=!OldName:- Deposit=TALLY!
set NewName=!NewName:-=.!
ren "!OldFile!" "!NewName!"
endlocal
)
pause