How to use xcopy to select specific folders(Not Files) within another folder

cmdcommand linexcopy

I am trying to xcopy specific folders from some directory to another folder, problem is i don't want to copy all the folders but i want specific folders. E.g. DirectorySource has folders (folderA,folderB,folderC) but i want to copy folderA and folderB only to DirectoryDestination.

Best Answer

Create a text file, say C:\excludes.txt with the following contents:

DirectorySource\folderC\

then you can copy:

xcopy DirectorySource DirectoryDestination /s /i /exclude:C:\excludes.txt

The file excludes.txt contains a list of strings, one per line. If a file or directory matches that string, then it will not be copied. If you want to exclude folder, it is safer to use the above string instead of simply folderC, which might skip a file called folderC_listing.txt