Richard
Richard

Reputation: 6116

CMD Command to Copy files with certain extension

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?

Upvotes: 8

Views: 27043

Answers (2)

stepanian
stepanian

Reputation: 11433

Add quotes just around the variable after the copy command:

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

Upvotes: 17

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.

Upvotes: 3

Related Questions