Anyone know how to make a batch file to replace all dashes (-) in a file name with periods (.)?
I basically have a ton of PDF files that are named like this:
HN TALLY 11-18-23.pdf
HN TALLY 11-19-23.pdf
REG 11-20-23.pdf
EW CAR 11-21-23.pdf
and so on....
I would like it to rename the files like this instead:
HN TALLY 11.18.23.pdf
HN TALLY 11.19.23.pdf
REG 11.20.23.pdf
EW CAR 11.21.23.pdf
Is that possible? Thanks for any help you can provide.
Batch file to replace - with . in file name
Moderator: DosItHelp
Re: Batch file to replace - with . in file name
CurrentFolderOnly.bat
Code: Select all
@echo off
cd /d "%~dp0"
for /f "delims=" %%i in ('dir /b /a-d *-*.pdf') do (
set "OldName=%%i"
setlocal enabledelayedexpansion
set NewName=!OldName:-=.!
ren "!OldName!" "!NewName!"
endlocal
)
Re: Batch file to replace - with . in file name
CurrentAndSubFolder.bat
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:-=.!
ren "!OldFile!" "!NewName!"
endlocal
)
Re: Batch file to replace - with . in file name
In your last question you were shown how to do string replacement. What was stopping you from attempting this on your own?data808 wrote: ↑04 Dec 2023 13:28Anyone know how to make a batch file to replace all dashes (-) in a file name with periods (.)?
I basically have a ton of PDF files that are named like this:
HN TALLY 11-18-23.pdf
HN TALLY 11-19-23.pdf
REG 11-20-23.pdf
EW CAR 11-21-23.pdf
and so on....
I would like it to rename the files like this instead:
HN TALLY 11.18.23.pdf
HN TALLY 11.19.23.pdf
REG 11.20.23.pdf
EW CAR 11.21.23.pdf
Is that possible? Thanks for any help you can provide.
Re: Batch file to replace - with . in file name
Thanks Squashman for pointing that out. I found that post and tried it myself with this code:
@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:-=.!
ren "!OldFile!" "!NewName!"
endlocal
)
Here is the result:
Original File:
ABC - Deposit 12-08-23.pdf
After running batch file:
ABC . Deposit 12.08.23.pdf
What I want it to be:
ABC TALLY 12.08.23.pdf
Would you know how to do this?
@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:-=.!
ren "!OldFile!" "!NewName!"
endlocal
)
Here is the result:
Original File:
ABC - Deposit 12-08-23.pdf
After running batch file:
ABC . Deposit 12.08.23.pdf
What I want it to be:
ABC TALLY 12.08.23.pdf
Would you know how to do this?
Re: Batch file to replace - with . in file name
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
Re: Batch file to replace - with . in file name
You should just change your name to BatchGPT.Batcher wrote: ↑20 Dec 2023 03:30Code: 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