BoundForGlory
BoundForGlory

Reputation: 4427

Exclude a directory using xcopy

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

Upvotes: 1

Views: 23077

Answers (2)

dbenham
dbenham

Reputation: 130919

Because the leading path in your exclude file does not match the leading path specified as your XCOPY source. Try fixing the path in the exclude file to match.

You could change the exclude line to read simply \Content\, but then it will exclude any file that has \Content\ anywhere in its path.

Note that the /EXCLUDE: option of XCOPY does a form of substring matching. Sometimes it is not precise enough to get the results you want. You should look into using ROBOCOPY instead.

Upvotes: 3

Chris Tybur
Chris Tybur

Reputation: 1622

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.

Upvotes: 3

Related Questions