How to replace space in file names
Posted: 14 Feb 2018 12:07
Hi,
I have these files in a folder ab and I want to replace the spaces in the file name to _.
XXXX_acc-er-in.pdf
xxxx_can mess comp-en-us.pdf
dddd_ee_le_ang-er-in.pdf
cccc_Rel File ope-in-er.pdf
xxx_etiti File ope-in-er.pdf
So it would be
XXXX_acc-er-in.pdf
xxxx_can_mess_comp-en-us.pdf
dddd_ee_le_ang-er-in.pdf
cccc_Rel_File_ope-in-er.pdf
xxx_etiti File_ope-in-er.pdf
Need help.
Can anyone please see, what's wrong in this? Ren is showing incorrect syntax.
Set "Pattern= "
Set "Replace=_"
For /f "delims=" %%a in ('dir /b /s %allTxtFiles%\*.txt') Do (
Set "File=%%~a"
echo "!File:%Pattern%=%Replace%!"
echo "%%a"
Ren "%%a" "!File:%Pattern%=%Replace%!"
)
I have these files in a folder ab and I want to replace the spaces in the file name to _.
XXXX_acc-er-in.pdf
xxxx_can mess comp-en-us.pdf
dddd_ee_le_ang-er-in.pdf
cccc_Rel File ope-in-er.pdf
xxx_etiti File ope-in-er.pdf
So it would be
XXXX_acc-er-in.pdf
xxxx_can_mess_comp-en-us.pdf
dddd_ee_le_ang-er-in.pdf
cccc_Rel_File_ope-in-er.pdf
xxx_etiti File_ope-in-er.pdf
Need help.
Can anyone please see, what's wrong in this? Ren is showing incorrect syntax.
Set "Pattern= "
Set "Replace=_"
For /f "delims=" %%a in ('dir /b /s %allTxtFiles%\*.txt') Do (
Set "File=%%~a"
echo "!File:%Pattern%=%Replace%!"
echo "%%a"
Ren "%%a" "!File:%Pattern%=%Replace%!"
)