I have a batch file to copy over files from Visual Studio to my Web folder. I want to copy all files in my web project, EXCEPT for *.cs files. I can’t seem to get this to work:
xcopy /r /d /i /s /y /exclude:".cs" C:\dev\apan C:\web\apan
Any tips? I just get exit code 4 when I try to run this.
The
/EXCLUDE:argument expects a file containing a list of excluded files.So create a file called
excludedfileslist.txtcontaining:Then a command like this:
Alternatively you could use Robocopy, but would require installing / copying a
robocopy.exeto the machines.Update
An anonymous comment edit which simply stated "This Solution exclude also css file!"
This is true creating a
excludedfileslist.txtfile contain just:(note no backslash on the end)
Will also exclude all of the following:
file1.csfile2.cssdir1.cs\file3.txtdir2\anyfile.cs.something.txtSometimes people don’t read or understand the XCOPY command’s help, here is an item I would like to highlight:
As the example states it excludes "all files with the .obj extension" but it doesn’t state that it also excludes files or directories named
file1.obj.tmpordir.obj.output\example2.txt.There is a way around
.cssfiles being excluded also, change theexcludedfileslist.txtfile to contain just:(note the backslash on the end).
Here is a complete test sequence for your reference:
This test was completed on a Windows 7 command line and retested on Windows 10 "10.0.14393".
Note that the last example does exclude
.\src\dir2.cs\file5.txtwhich may or may not be unexpected for you.