I\'m trying to rename all the files inside a folder (all .exe files). I want to replace all the spaces with underscores, e.g. qwe qwe qwe asd.exe to qwe_q
Based on @Gray answer, I have extending it to replace filenames recursively in all subdirectories.
File 1: replace.bat
setlocal enabledelayedexpansion
set "pattern= "
set "replace=_"
for %%I in (*.ext) do (
set "file=%%~I"
ren "%%I" "!file:%pattern%=%replace%!"
)
File 2: recursive.bat
for /d /r . %%D in (*) do (
copy replace.bat "%%D\replace.bat"
cd "%%D"
replace.bat
del replace.bat
cd..
)
Files
replace.bat contains script to replace space with underscorerecursive.bat contains script to do recursion in all subdirectoriesHow to use?
replace.bat and recursive.bat in same directory..ext with desired file extension to match (like .mp4) in replace.bat.recursive.bat file.