How do I use Nant/Ant naming patterns?
Asked Answered
L

4

121

I have to admit that I always forgot the syntactical intracacies of the naming patterns for Nant (eg. those used in filesets). The double asterisk/single asterisk stuff seems to be very forgettable in my mind.

Can someone provide a definitive guide to the naming patterns?

Laurinelaurita answered 16/9, 2008 at 6:35 Comment(2)
I have read the reference. And re-read it. And re-read it. I just think it has a really poor set of examples and is unclear in its message.Laurinelaurita
Maybe you can specify exactly what you're trying to achive and someone can provide a better answer?Rogers
S
295

The rules are:

  • a single star (*) matches zero or more characters within a path name
  • a double star (**) matches zero or more characters across directory levels
  • a question mark (?) matches exactly one character within a path name

Another way to think about it is double star (**) matches slash (/) but single star (*) does not.

Let's say you have the files:

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

Then the patterns:

  • *.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    
Sorrows answered 17/9, 2008 at 19:49 Comment(10)
I think that this is a much better explanation than the Nant reference. Cheers!Laurinelaurita
What does src/*/** match? I would expect it to be 4, but my experience with maven seems to indicate that you match any files in any folders you need src/*/*/**Marinamarinade
what would **.c match?Darlington
I don't use Ant any more, so I'm not in a place to answer follow-up questions. You should ask a new question or, even better, find the answer and then submit an edit to my answer.Sorrows
What if there is a space in the path? #37732263Takeoff
Can someone explain the rationale behind why **/bar.* matches bar.txt, which does not contain a slash?Mimas
@Mimas One way to think about it is that bar.txt is implicitly ./bar.txt (. means the current directory). So that list is really ./bar.txt, ./src/bar.c, etc. and the ./ is assumed.Sorrows
How'd I match zero or one character, for example both test.yaml and test.yml? test.y*ml works but is too wide.Standardbearer
@AbhijitSarkar I don't know! You should post a new question so that more people see it. This one is over nine years old!Sorrows
The missing example: **. matches 1, 2, 3, and 4Expediential
O
24

Here's a few extra pattern matches which are not so obvious from the documentation. Tested using NAnt for the example files in benzado's answer:

  1. bar.txt
  2. src/bar.c
  3. src/baz.c
  4. src/test/bartest.c
  • 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
Oquinn answered 14/8, 2013 at 13:33 Comment(1)
small note: with ant (1.8.2) **.c is no replacement for **/*.cKirsten
E
6

Double asterisks (**) are associated with the folder-names matching, whereas single symbols asterisk (* = multi characters) as well as the question-mark (? = single character) are used to match the file-names.

Endogenous answered 11/1, 2012 at 14:47 Comment(0)
R
4

Check out the Nant reference. The fileset patterns are:

'*' matches zero or more characters, e.g. *.cs
'?' matches one character, e.g. ?.cs

And '**' matches a directory tree e.g. src/**/*.cs will find all cs files in any sub-directory of src.

Rogers answered 16/9, 2008 at 7:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.