<fileset>

Filesets are groups of files. These files can be found in a directory tree starting in a base directory and are matched by patterns taken from a number of patterns. Filesets can appear inside tasks that support this feature or at the project level, i.e., as children of <project>.

Patterns

As described earlier, patterns are used for the inclusion and exclusion. These patterns look very much like the patterns used in DOS and UNIX:

  • '*' matches zero or more characters

    For example:

    *.cs matches .cs, x.cs and FooBar.cs, but not FooBar.xml (does not end with .cs).

  • '?' matches one character

    For example:

    ?.cs matches x.cs, A.cs, but not .cs or xyz.cs (both don't have one character before .cs).

Combinations of *'s and ?'s are allowed.

Matching is done per-directory. This means that first the first directory in the pattern is matched against the first directory in the path to match. Then the second directory is matched, and so on. For example, when we have the pattern /?abc/*/*.cs and the path /xabc/foobar/test.cs, the first ?abc is matched with xabc, then * is matched with foobar, and finally *.cs is matched with test.cs. They all match, so the path matches the pattern.

To make things a bit more flexible, we added one extra feature, which makes it possible to match multiple directory levels. This can be used to match a complete directory tree, or a file anywhere in the directory tree. To do this, ** must be used as the name of a directory. When ** is used as the name of a directory in the pattern, it matches zero or more directories. For example: /test/** matches all files/directories under /test/, such as /test/x.cs, or /test/foo/bar/xyz.html, but not /xyz.xml.

There is one "shorthand" - if a pattern ends with / or \, then ** is appended. For example, mypackage/test/ is interpreted as if it were mypackage/test/**.

Case-Sensitivity

By default, pattern matching is case-sensitive on Unix and case-insensitive on other platforms. The NAnt.Core.Types.FileSet.CaseSensitive parameter can be used to override this.

Default Excludes

There are a set of definitions that are excluded by default from all tasks that use filesets. They are:

  • **/.svn
  • **/.svn/**
  • **/_svn
  • **/_svn/**
  • **/.git
  • **/.git/**
  • **/.git* (eg. .gitignore)
  • **/.hg
  • **/.hg/**
  • **/.hg* (eg. .hgignore)
  • **/SCCS
  • **/SCCS/**
  • **/vssver.scc
  • **/vssver2.scc
  • **/_vti_cnf/**
  • **/*~
  • **/#*#
  • **/.#*
  • **/%*%
  • **/CVS
  • **/CVS/**
  • **/.cvsignore
  • **/._*
  • **/.bzr
  • **/.bzr/**
  • **/.bzr* (eg. .bzrignore)
  • **/.DS_Store

If you do not want these default excludes applied, you may disable them by setting NAnt.Core.Types.FileSet.DefaultExcludes to false.

Parameters

Attribute Type Description Required
basedir directory
The base of the directory of this fileset. The default is the project base directory.
False
casesensitive bool
Indicates whether include and exclude patterns must be treated in a case-sensitive way. The default is true on Unix; otherwise, false.
False
defaultexcludes bool
Indicates whether default excludes should be used or not. The default is true.
False
failonempty bool
When set to true, causes the fileset element to throw a NAnt.Core.ValidationException when no files match the includes and excludes criteria. The default is false.
False
id string
The ID used to be referenced later.
False
refid string
The ID to use as the reference.
False

Nested elements

<exclude>

The items to exclude from the fileset.

Automatically validates attributes in the element based on attributes applied to members in derived classes.

Parameters

Attribute Type Description Required
name string
The pattern or file name to exclude.
True
if bool
If true then the pattern will be excluded; otherwise, skipped. The default is true.
False
unless bool
Opposite of NAnt.Core.Types.FileSet.Exclude.IfDefined. If false then the pattern will be excluded; otherwise, skipped. The default is false.
False

<exclude>

<excludesfile>

The files from which a list of patterns or files to exclude should be obtained.

Automatically validates attributes in the element based on attributes applied to members in derived classes.

Parameters

Attribute Type Description Required
name file
The name of a file; each line of this file is taken to be a pattern.
True
if bool
If true then the patterns will be excluded; otherwise, skipped. The default is true.
False
unless bool
Opposite of NAnt.Core.Types.FileSet.ExcludesFile.IfDefined. If false then the patterns will be excluded; otherwise, skipped. The default is false.
False

<excludesfile>

<include>

The items to include in the fileset.

Automatically validates attributes in the element based on attributes applied to members in derived classes.

Parameters

Attribute Type Description Required
name string
The pattern or file name to include.
True
asis bool
If true then the file name will be added to the NAnt.Core.Types.FileSet without pattern matching or checking if the file exists. The default is false.
False
frompath bool
If true then the file will be searched for on the path. The default is false.
False
if bool
If true then the pattern will be included; otherwise, skipped. The default is true.
False
unless bool
Opposite of NAnt.Core.Types.FileSet.Include.IfDefined. If false then the pattern will be included; otherwise, skipped. The default is false.
False
if bool
If true then the pattern will be excluded; otherwise, skipped. The default is true.
False
name string
The pattern or file name to exclude.
True
unless bool
Opposite of NAnt.Core.Types.FileSet.Exclude.IfDefined. If false then the pattern will be excluded; otherwise, skipped. The default is false.
False

<include>

<includesfile>

The files from which a list of patterns or files to include should be obtained.

Automatically validates attributes in the element based on attributes applied to members in derived classes.

Parameters

Attribute Type Description Required
asis bool
If true then the patterns in the include file will be added to the NAnt.Core.Types.FileSet without pattern matching or checking if the file exists. The default is false.
False
frompath bool
If true then the patterns in the include file will be searched for on the path. The default is false.
False
if bool
If true then the patterns will be included; otherwise, skipped. The default is true.
False
unless bool
Opposite of NAnt.Core.Types.FileSet.IncludesFile.IfDefined. If false then the patterns will be included; otherwise, skipped. The default is false.
False
if bool
If true then the patterns will be excluded; otherwise, skipped. The default is true.
False
name file
The name of a file; each line of this file is taken to be a pattern.
True
unless bool
Opposite of NAnt.Core.Types.FileSet.ExcludesFile.IfDefined. If false then the patterns will be excluded; otherwise, skipped. The default is false.
False

<includesfile>

<excludes>

The items to exclude from the fileset.

Obsolete. Use element instead.

Automatically validates attributes in the element based on attributes applied to members in derived classes.

Parameters

Attribute Type Description Required
name string
The pattern or file name to exclude.
True
if bool
If true then the pattern will be excluded; otherwise, skipped. The default is true.
False
unless bool
Opposite of NAnt.Core.Types.FileSet.Exclude.IfDefined. If false then the pattern will be excluded; otherwise, skipped. The default is false.
False

<excludes>

<includes>

The items to include in the fileset.

Obsolete. Use element instead.

Automatically validates attributes in the element based on attributes applied to members in derived classes.

Parameters

Attribute Type Description Required
name string
The pattern or file name to include.
True
asis bool
If true then the file name will be added to the NAnt.Core.Types.FileSet without pattern matching or checking if the file exists. The default is false.
False
frompath bool
If true then the file will be searched for on the path. The default is false.
False
if bool
If true then the pattern will be included; otherwise, skipped. The default is true.
False
unless bool
Opposite of NAnt.Core.Types.FileSet.Include.IfDefined. If false then the pattern will be included; otherwise, skipped. The default is false.
False
if bool
If true then the pattern will be excluded; otherwise, skipped. The default is true.
False
name string
The pattern or file name to exclude.
True
unless bool
Opposite of NAnt.Core.Types.FileSet.Exclude.IfDefined. If false then the pattern will be excluded; otherwise, skipped. The default is false.
False

<includes>

<includesList>

The files from which a list of patterns or files to include should be obtained.

Obsolete. Use instead.

Automatically validates attributes in the element based on attributes applied to members in derived classes.

Parameters

Attribute Type Description Required
asis bool
If true then the patterns in the include file will be added to the NAnt.Core.Types.FileSet without pattern matching or checking if the file exists. The default is false.
False
frompath bool
If true then the patterns in the include file will be searched for on the path. The default is false.
False
if bool
If true then the patterns will be included; otherwise, skipped. The default is true.
False
unless bool
Opposite of NAnt.Core.Types.FileSet.IncludesFile.IfDefined. If false then the patterns will be included; otherwise, skipped. The default is false.
False
if bool
If true then the patterns will be excluded; otherwise, skipped. The default is true.
False
name file
The name of a file; each line of this file is taken to be a pattern.
True
unless bool
Opposite of NAnt.Core.Types.FileSet.ExcludesFile.IfDefined. If false then the patterns will be excluded; otherwise, skipped. The default is false.
False

<includesList>

Examples

Match Matches all files in CVS directories that can be located anywhere in the directory tree. Matches: CVS/Repository org/apache/CVS/Entries org/apache/jakarta/tools/ant/CVS/Entries But not: org/apache/CVS/foo/bar/Entries (foo/bar/ part does not match) Matches all files in the org/apache/jakarta directory tree. Matches: org/apache/jakarta/tools/ant/docs/index.html org/apache/jakarta/test.xml But not: org/apache/xyz.java (jakarta/ part is missing) Matches all files in CVS directories that are located anywhere in the directory tree under org/apache. Matches: org/apache/CVS/Entries org/apache/jakarta/tools/ant/CVS/Entries But not: org/apache/CVS/foo/bar/Entries (foo/bar/ part does not match) Matches all files that have a test element in their path, including test as a filename.
Pattern
**/CVS/*
org/apache/jakarta/**
org/apache/**/CVS/*
**/test/**

See Also

  • NAnt.Core.Types.PatternSet

Requirements

Assembly
NAnt.Core.dll
Namespace
NAnt.Core.Types