Ant Pattern Matching - * vs. **

jakejgordon picture jakejgordon · Oct 29, 2015 · Viewed 10.2k times · Source

We are using TeamCity to produce *.nupkg artifacts which we don't want to be cleaned up. TeamCity provides a field where you can specify an ANT-style pattern for indicating which files you do or don't want to be cleaned up. Let's assume for a second that we have the following files which we do not want to be cleaned up:

/a.nupkg
/dir1/b.nupkg
/dir1/dir2/c.nupkg

Does the *.nupkg pattern match .nupkg files both in the root directory AND all child directories or do need to use **.*nupkg to traverse all directories?

I read the following documentation but this is still ambiguous to me: http://ant.apache.org/manual/dirtasks.html#patterns

If there is an Ant-Pattern tester (similar to http://regexpal.com/) that would be amazing.

Answer

Verhagen picture Verhagen · Oct 29, 2015

To match all files, in all directories (from the base directory and deeper)

**/*.nupkg

Will match

sample.nupkg
sample-2.nupkg
tmp/sample.nupkg
tmp/other.nupkg
other/new/sample.nupkg

** will match any directory (multiple directories deep).

*.nupkg will match any file with the nupkg extension. Or just * will match any file or any directory (but just a single directory deep).

PS: There is no Ant Pattern Tester.