3

How do you copy specific file types from one folder into another folder while retaining the folder structure?

The following batch command is capable of copying the specific file types to a folder, but lacks being able to retain the folder structure:

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

How could I modify this to keep the folder structure from the source? Thanks!

code
  • 5,294
  • 16
  • 62
  • 113

1 Answers1

5
xcopy /e c:\source\*.xml x:\destination\

should do the job.

See

xcopy /?

from the prompt for documentation. Use /e for with-empty-directories or /s for to ignore empty directories.

Magoo
  • 77,302
  • 8
  • 62
  • 84
  • Thank you Peter Wright! Saved my life. How would I put multiple file types in there without having to write a new line? – code Apr 01 '13 at 23:30
  • 3
    `FOR %%t in (ext1 ext2) do xcopy /e c:\source\*.%%t x:\destination\` should do that job - where `ext1 ext2` could be virtually any number of extensions – Magoo Apr 01 '13 at 23:37