3
votes

I am working on an ANT pattern parser as part of a large server project.

There are some good examples of ANT patterns in the answer to this post: How do I use Nant/Ant naming patterns? however, I am still confused about some possible permutations.

One of the examples on the ANT pattern documentation here http://nant.sourceforge.net/release/0.85/help/types/fileset.html is as follows:

**/test/** Matches all files that have a test element in their path, including test as a filename.

My understanding is that ** matches one or more directories and also files under those directories. So I would expect **/test/** to match src/test/subfolder/file.txt and test/file2.txt but this statement seems to imply that it would also match a file named src/test. Is this correct even though there is a / after the test in the pattern?

Also, its not clear whether the following patterns would be valid:

folder**
folder1/folder**
**folder/file.txt

I would imagine that they would work the same as

folder*/**
folder1/folder*/**
**/*folder/file.txt

but are they allowed?

1
Create some folders and empty files, write a test build file with <pathconvert> and <fileset>, and you will see how the patterns actually work.coolcfan
Good point but I guess I was hoping to learn the pattern syntax without actually learning to use NAnt...sparkplug

1 Answers

6
votes

I did some testing with NAnt as per coolcfan's suggestion and answered my own question. The patterns in the question are all valid.

Based on the following files from the link in my question above:

  1. bar.txt
  2. src/bar.c
  3. src/baz.c
  4. src/test/bartest.c

The following unexpected patterns are also valid:

  • src**                      matches 2, 3 and 4
  • **.c                        matches 2, 3, and 4
  • **ar.*                    matches 1 and 2
  • **/bartest.c/**  matches 4
  • src/ba?.c/**        matches 2 and 3

For completeness, these are in addition to the following patterns taken from the link in my question above:

  • *.c             matches nothing (there are no .c files in the current directory)
  • src/*.c     matches 2 and 3
  • */*.c         matches 2 and 3 (because * only matches one level)
  • **/*.c       matches 2, 3, and 4 (because ** matches any number of levels)
  • bar.*         matches 1
  • **/bar.*   matches 1 and 2
  • **/bar*.* matches 1, 2, and 4
  • src/ba?.c matches 2 and 3