Cmd command to copy files with a specific extension

So, I use this command to copy only txt files from a specific directory to another directory

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

But it only copies text files with no space in the name, so it copies test.txt, but does not test 2.txt. How to make it copy txt files with spaces?

+6
cmd
source share
2 answers

Add quotes around the variable after the copy command:

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

what happened 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. Then Nevermind.

+2
source share

All Articles