Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

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

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?


share|improve this question
up vote 2 down vote accepted

You need to use quotations around literal strings containing spaces.

FOR /R C:\Users\user\Desktop\New^ folder^ 3\ %%F IN (folder\*.*) DO (
    MOVE "%%~F" "C:\Users\user\Desktop\New folder\"
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: and – David Ruhmann Dec 13 '12 at 20:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .