Windows command forfiles to copy subdirectories

Using the forfiles Windows command, I wnat to copy a directory and every subdirectory. To do so, I´ve tried this:

forfiles /S /P  %myDirectoryPath% /C "CMD /C xcopy @path %NewPath% /Y /V /E"

But all files included in the subdirectories are copied in the same folder as the files of the main directory.

How can I solve it?

Thanks.

Upvotes: 0

Views: 7849

Answers (1)

Bali C
Bali C

Reputation: 31221

You should be able to use xcopy to copy the directory tree

xcopy %myDirectoryPath% %NewPath% /t /e

Alternatively use robocopy

robocopy %myDirectoryPath% %NewPath% /e /create

Upvotes: 1

Related Questions