The use of FOR /R

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
tinfanide
Posts: 117
Joined: 05 Sep 2011 09:15

The use of FOR /R

#1 Post by tinfanide » 10 Nov 2011 08:17

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?

Post Reply