I have a single-line script that copies all ".ext1" files from current folder to destination folder recursively:
xcopy *.ext1 D:\dest /s /d /y
It works perfectly.
Now I want to copy all *.ext2 as well. Instead of copy-pasting (that works fine):
xcopy *.ext1 D:\dest /s /d /y
xcopy *.ext2 D:\dest /s /d /y
I want to use a for
command:
for %%f in (*.ext1 *.ext2) do xcopy %%f D:\dest /s /d /y
but it does not work:
- It does not copy subdirs of source folder
- It does not copy files with names with spaces like "read me.ext1"
I tried to use a /R
key:
for /R %%f in (*.ext1 *.ext2) do xcopy %%f D:\dest /s /d /y
but it resulted in copying subdir source files into the root folder of dest. And names with spaces did not go.
What is a correct form of the for
command would be?
Best Answer
try this: