tags:

views:

67

answers:

2

So I'm using this command to copy only txt files from a certain directory to another directory

for /R c:\source %%f in (*.xml) do copy %%f x:\destination\

But it only copies over the text files without a space in the name, so it copies test.txt but not test 2.txt. How do I make it so it copies txt files with spaces?

+3  A: 

Add quotes around the variable names:

for /R c:\source "%%f" in (*.xml) do copy "%%f" x:\destination\
Ralph Stevens
The best and only answer...
Emtucifor
It's probably worth explaining that you need quotes around files with spaces in them in your answer. I stared at this for a few seconds before I noticed what was different.
Joshua McKinnon
Added a note regarding quotes. Thanks.
Ralph Stevens
A: 

What's wrong with

copy c:\source\*.xml x:\destination\ >nul

[Edit] Oh I see, you want to copy all the files in all directories recursively, but without copying the directory structure. Nevermind, then.

BlueRaja - Danny Pflughoeft