I have a bunch of PDF files in a folder and they are all named like this:
Tally Cash Date 11.29.23.pdf
I would like to just remove the words "Cash" and "Date" in the file name so they all show like this:
Tally 11.29.23.pdf
Does anyone know how to make a batch file that can do this? I looked online and only could find batch files to remove the beginning or ending of a file name.
Any help is appreciated. Thank you.
Batch File To Remove Word In Filename
Moderator: DosItHelp
Re: Batch File To Remove Word In Filename
test-1.bat
Code: Select all
@echo off
cd /d "%~dp0"
for /f "delims=" %%i in ('dir /b /a-d *.pdf ^| findstr /i /c:"Cash" /c:"Date"') do (
set "OldName=%%i"
setlocal enabledelayedexpansion
set "NewName=!OldName:Cash=!"
set "NewName=!NewName:Date=!"
set "NewName=!NewName: = !"
set "NewName=!NewName: = !"
echo "!OldName!" ---^> "!NewName!"
ren "!OldName!" "!NewName!"
endlocal
)
pause
Re: Batch File To Remove Word In Filename
Thank you so much for the help. Works great!