Code: Select all
@echo on
for /r "C:\test\" %%G in (*.*) do (
setlocal enabledelayedexpansion
set old=%%G
set new=!old: =_!
move "!old!" "!new!"
)
pause
File Structure:
test:
- file 2.txt
file 1.txt
folder 1
test.bat
folder 1:
- folder 2
file 3.txt
folder 2:
file 4.txt
test.bat is the batch file where I'm writing the codes in.
I want all the file.txt to have no space and the spaces are replaced with "_".
I don't know why file 3.txt and file 4.txt were reported that "cannot find the specific path".
If I change folder 1 to folder_1 (no space), it works.
How can I fix that even folder names contain space?