Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am attempting to loop through all the files in the "folder" folders in the specified folder, and move them to a different one.

I have this code:

@ECHO OFF
FOR /R C:\Users\user\Desktop\New^ folder^ 3\ %%F IN (folder\*.*) DO (
    MOVE %%F C:\Users\user\Desktop\New^ folder\
)
PAUSE

But it brings out a syntax error. However, When I ECHO %%F, it shows the full path of each file correctly.

What am I doing wrong here?

Thanks.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

You need to use quotations around literal strings containing spaces.

@ECHO OFF
FOR /R C:\Users\user\Desktop\New^ folder^ 3\ %%F IN (folder\*.*) DO (
    MOVE "%%~F" "C:\Users\user\Desktop\New folder\"
)
PAUSE
share|improve this answer
    
It worked like a charm, mind explaining what the '~' means exactly, and why can't I use '^' in the second parameter? –  bruneti12 Dec 13 '12 at 20:28
    
@bruneti12 The tilde ~ removes (if any) the surrounding quotations from the variable. The reason you cannot just escape ^ the spaces is because MOST programs are very strict about using spaces as their parameter delimiters. Therefore if you want a whole path, containing spaces, sent as a single parameter to the move command; it must be within quotes. For more information on variable modifiers see call /?. Here are some great batch reference sites: robvanderwoude.com and ss64.com –  David Ruhmann Dec 13 '12 at 20:37
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.