Windows – Exclude a directory using xcopy

copyvisual studio 2010windows

I have a .bat file that publishes my VS2010 application, then copies the files to a location on my test webserver so i dont have to manually do it. I have a couple of directories i dont want to copy everytime because the contents wont change, and there are a ton of files. Heres my xcopy command:

 XCOPY C:\Publish\NewPCloser\* \\testserver\c$\NewPCloser /s /i /Y /EXCLUDE:c:\exclude.txt

Heres my exclude.txt file:

  web.config
  c:\Working\PaperlessCloser4.0\PaperlessCloser4.0\Content

It excludes the web.config, but it still copies the Content folder and all 300+ files. How do i exclude a directory and from copying via xcopy? Thanks

Best Answer

According to this, to exclude a directory you would simply add it to the exclusion file like any other string, but it needs to have a backslash at the beginning and end of its name. So if you have a directory called Content within the directory you are copying, you should be able to add \Content\ to your exclusion file and it should ignore any files whose path contains that string.