Windows 7 Copy certain files using command prompt recreating folder structure


Honorable Member
At the moment I am using an xcopy command to copy all files with a certain extension to another folder. As the number of files in this folder increases I'd like to organise them into sub folders and have the directory structure mirrored. However I don't want the entire folder contents copied over as there are files not needed in the destination.

My command is currently this
XCOPY "$(ProjectDir)usercontrols\*.ascx" "..\..\..\Website\usercontrols\" /Y
If I organise my ascx files into sub directories, can xcopy recreate the structure but only copying the .ascx files needed in the destination. Or is there another command line utility that can do so.


Honorable Member
Did a big more googling and found out about the robocopy utility. The following using that seems to work

ROBOCOPY "$(ProjectDir)usercontrols" "..\..\..\Website\usercontrols" *.ascx /copy:TD /s /xx /njh /np


Senior Member
Microsoft MVP
I was going to suggest robocopy as well before I seen that it was also suggested here. I like the fact that it's also a threading capable utility for multiple operations running asynchronously, but in general it's configurability is a +1 from me. I use it to backup my development projects folder.

This website is not affiliated, owned, or endorsed by Microsoft Corporation. It is a member of the Microsoft Partner Program.