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.
我必须承认,我总是忘记Nant命名模式的语法内在(例如,文件集中使用的那些)。在我看来,双星号/单星号的东西似乎是非常容易忘记的。
Can someone provide a definitive guide to the naming patterns?
有人可以提供命名模式的权威指南吗?
4 个解决方案
#1
200
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:
假设你有文件:
- bar.txt
- src/bar.c
- src/baz.c
- 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
* .c没有匹配(当前目录中没有.c文件)
src / * .c匹配2和3
* / * .c匹配2和3(因为*只匹配一个级别)
** / * .c匹配2,3和4(因为**匹配任意数量的级别)
吧。*匹配1
** / bar。*匹配1和2
** / bar *。*匹配1,2和4
src / ba?.c匹配2和3
#2
12
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:
这里有一些额外的模式匹配,从文档中不是那么明显。在benzado的答案中使用NAnt测试示例文件:
-
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
src **匹配2,3和4
**。c匹配2,3和4
** ar。*匹配1和2
** / bartest.c / **匹配4
src / ba?.c / **匹配2和3
#3
3
Check out the Nant reference. The fileset patterns are:
查看Nant参考。文件集模式是:
'*' matches zero or more characters, e.g. *.cs
'?' matches one character, e.g. ?.cs
'*'匹配零个或多个字符,例如* .cs'?'匹配一个字符,例如?的.cs
And '**' matches a directory tree e.g. src/**/*.cs will find all cs files in any sub-directory of src.
并且'**'匹配目录树,例如src / ** / * .cs将在src的任何子目录中找到所有cs文件。
#4
3
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.
双星号(**)与文件夹名称匹配相关联,而单个符号星号(* =多个字符)以及问号(?=单个字符)用于匹配文件名。
#1
200
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:
假设你有文件:
- bar.txt
- src/bar.c
- src/baz.c
- 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
* .c没有匹配(当前目录中没有.c文件)
src / * .c匹配2和3
* / * .c匹配2和3(因为*只匹配一个级别)
** / * .c匹配2,3和4(因为**匹配任意数量的级别)
吧。*匹配1
** / bar。*匹配1和2
** / bar *。*匹配1,2和4
src / ba?.c匹配2和3
#2
12
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:
这里有一些额外的模式匹配,从文档中不是那么明显。在benzado的答案中使用NAnt测试示例文件:
-
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
src **匹配2,3和4
**。c匹配2,3和4
** ar。*匹配1和2
** / bartest.c / **匹配4
src / ba?.c / **匹配2和3
#3
3
Check out the Nant reference. The fileset patterns are:
查看Nant参考。文件集模式是:
'*' matches zero or more characters, e.g. *.cs
'?' matches one character, e.g. ?.cs
'*'匹配零个或多个字符,例如* .cs'?'匹配一个字符,例如?的.cs
And '**' matches a directory tree e.g. src/**/*.cs will find all cs files in any sub-directory of src.
并且'**'匹配目录树,例如src / ** / * .cs将在src的任何子目录中找到所有cs文件。
#4
3
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.
双星号(**)与文件夹名称匹配相关联,而单个符号星号(* =多个字符)以及问号(?=单个字符)用于匹配文件名。