Have you ever struggled with the
/EXCLUDE switch for the good ol´
xcopy DOS command? Well...I have...and the pitfalls described below shows that it can be a bit tricky.
Mission
Copy the content (files and subfolders) from a source directory to a given destination, but exclude some of the files in the source directory. The context in my case was a post-build event in a Visual Studio project that should perform a "developer deploy" to my local Sharepoint site.
Below is the folder structure in Visual Studio that I wanted to copy.
- All .ascx files under CONTROLTEMPLATES should be copied, but the *.cs files should be excluded.
- All files under IMAGES should be copied.
- All files under LAYOUTS should be copied, except from the *.cs files.

Solution
The
xcopy /EXCLUDE switch
. Should be easy enough...
Pitfalls- The /EXCLUDE:file1[+file2]... switch does not take a set of file-/foldernames that shall be excluded as parameter, but a set of textfiles that contains the file-/foldernames to exclude.
- The textfile(s) specifying the files to exclude uses CR+LF as delimitter for each filter string.
- The filter string can not include wildcards such as *.cs.
- The first line in the textfile(s) shall always be a CR+LF since that line will be skipped.
My post-build script that did the trickREM === copy .dll to bin folder ===copy "$(TargetPath)" "C:\Inetpub\wwwroot\wss\VirtualDirectories\80\bin\" /yREM === copy CONTROLTEMPLATES ===xcopy "$(ProjectDir)CONTROLTEMPLATES\*" "c:\program files\common files\microsoft shared\web server extensions\12\Template\CONTROLTEMPLATES" /E /I /Y /EXCLUDE:$(ProjectDir)XcopyExclude.txtREM === copy IMAGES===xcopy "$(ProjectDir)IMAGES\*" "c:\program files\common files\microsoft shared\web server extensions\12\Template\IMAGES" /E /I /Y /EXCLUDE:$(ProjectDir)XcopyExclude.txtREM === copy LAYOUTS ===xcopy "$(ProjectDir)LAYOUTS\*" "c:\program files\common files\microsoft shared\web server extensions\12\Template\LAYOUTS" /E /I /Y /EXCLUDE:$(ProjectDir)XcopyExclude.txtThe XcopyExclude.txt contentCR+LF <---- IMPORTANT!.ascx.cs
.ascx.designer.cs
.aspx.cs
.aspx.designer.cs
.Master.cs
.Master.designer.csNote 1): The first line
must (for some strange reason)
include a CR+LF, since the first line always will be skipped.
Note 2) A single .cs filter would
almost have done the trick, but in my specific case such a filter would have excluded the style.css file aswell.
And the soundtrack for this post?
http://www.deezer.com/track/120075