Search code examples
filexcopy

How do I limit the file matching of the xcopy exclusion list


I am running into an issue where xcopy matches file names that I didn't expect it to match... Some file names have patterns in them that match a file extension that I'm trying to exclude. Unfortunately xcopy simply matches patterns...

My exclusion file is configured to exclude .xml files, but the source directory contains two project outputs (Acme.XML.dll and Acme.XML.Providers.dll), which get caught by the filter and excluded.

The copy script that we use is a common script for all projects we work with, so I really don't want to do a "one-off" modification, just for these two projects. I would also like to stay with a solution that involves a file list of exclusions. This script is configured in the build events of 30+ VS.NET projects, so updating a file when requirements change, is much easier that modifying all the projects...

XCOPY Command:

 xcopy "C:\MNT\Dev\SRC\Acme\TestProject\bin\Release\*.*" "C:\MNT\Dev\Acme\ClassLibraries\AnyCPU\Release" /I /Y /EXCLUDE:C:\MNT\Dev\BuildExclusionList_Release.txt

Contents of BuildExclusionList_Release.txt

.tmp
DAL_GENERATED_FLAG.TXT
.xml

Solution

  • I was able to answer this question after several hours of digging around the web. As it turns out, simply appending a backslash \ to the item in the exclusion list will limit its matching to the end of a file name, in addition to a path name.

    I had assumed that slashes only applied to folders, but xcopy applies them to file names as well. Using .xml\, allowed me to exclude Acme.XML.xml (The XML documentation), but not Acme.XML.dll (The project output)

    Updated BuildExclusionList_Release.txt

    .tmp\
    DAL_GENERATED_FLAG.TXT
    .xml\
    

    Project Build Output

    Acme.XML -> C:\MNT\Dev\SRC\Acme\XML\bin\Release\Acme.XML.dll
    xcopy "C:\MNT\Dev\SRC\Acme\XML\bin\Release\*.*" "C:\MNT\Dev\Acme\ClassLibraries\AnyCPU\Release" /I /Y /EXCLUDE:C:\MNT\Dev\Acme\BuildExclusionList_Release.txt
    C:\MNT\Dev\SRC\Acme\XML\bin\Release\Acme.Common.dll
    C:\MNT\Dev\SRC\Acme\XML\bin\Release\Acme.Logging.dll
    C:\MNT\Dev\SRC\Acme\XML\bin\Release\Acme.XML.dll
    C:\MNT\Dev\SRC\Acme\XML\bin\Release\Acme.Math.dll
    4 File(s) copied
    ========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========