You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/pipelines/tasks/file-matching-patterns.md
+63-20Lines changed: 63 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,8 +2,9 @@
2
2
title: File matching patterns reference
3
3
description: A reference guide that can help you to understand the file matching patterns for Azure Pipelines and Team Foundation Server (TFS).
4
4
ms.topic: reference
5
+
ai-usage: ai-assisted
5
6
ms.assetid: 8A92C09C-3EE2-48EF-A2C0-3B2005AACFD7
6
-
ms.date: 12/13/2019
7
+
ms.date: 06/24/2025
7
8
monikerRange: '<= azure-devops'
8
9
---
9
10
@@ -18,12 +19,19 @@ File and directory names are compared to patterns to include (or sometimes exclu
18
19
You can build up complex behavior by stacking multiple patterns.
19
20
See [fnmatch](http://man7.org/linux/man-pages/man3/fnmatch.3.html) for a full syntax guide.
20
21
22
+
-[Match characters](#match-characters)
23
+
-[Extended globbing](#extended-globbing)
24
+
-[Comments](#comments)
25
+
-[Exclude patterns](#exclude-patterns)
26
+
-[Escaping](#escaping)
27
+
-[Slash](#slash)
28
+
21
29
### Match characters
22
30
23
31
Most characters are used as exact matches.
24
32
What counts as an "exact" match is platform-dependent:
25
33
the Windows filesystem is case-insensitive, so the pattern "ABC" would match a file called "abc".
26
-
On case-sensitive filesystems, that pattern and name would not match.
34
+
On case-sensitive filesystems, that pattern and name wouldn't match.
27
35
28
36
The following characters have special behavior.
29
37
@@ -33,41 +41,57 @@ The following characters have special behavior.
33
41
*`**` recursive wildcard. For example, `/hello/**/*` matches all descendants of `/hello`.
34
42
35
43
### Extended globbing
36
-
*`?(hello|world)` - matches `hello` or `world` zero or one times
44
+
45
+
*`?(hello|world)` - matches `hello` or `world` zero times or one time
37
46
*`*(hello|world)` - zero or more occurrences
38
47
*`+(hello|world)` - one or more occurrences
39
48
*`@(hello|world)` - exactly once
40
49
*`!(hello|world)` - not `hello` or `world`
41
50
42
-
Note, extended globs cannot span directory separators. For example, `+(hello/world|other)` is not valid.
51
+
> [!NOTE]
52
+
> Extended globs can't span directory separators. For example, `+(hello/world|other)` isn't valid.
43
53
44
54
### Comments
55
+
45
56
Patterns that begin with `#` are treated as comments.
46
57
47
58
### Exclude patterns
59
+
48
60
Leading `!` changes the meaning of an include pattern to exclude.
49
61
You can include a pattern, exclude a subset of it, and then re-include a subset of that:
50
62
this is known as an "interleaved" pattern.
51
63
52
64
Multiple `!` flips the meaning. See <ahref="#doubleexcl_examples">examples</a>.
53
65
54
-
You must define an include pattern before an exclude one. See <ahref="#character_set_examples">examples</a>.
66
+
You must define an include pattern before an exclude pattern. See <ahref="#character_set_examples">examples</a>.
55
67
56
68
### Escaping
69
+
70
+
57
71
Wrapping special characters in `[]` can be used to escape literal glob characters in a file name. For example the literal file name `hello[a-z]` can be escaped as `hello[[]a-z]`.
58
72
59
73
### Slash
74
+
60
75
`/` is used as the path separator on Linux and macOS.
61
76
Most of the time, Windows agents accept `/`.
62
77
Occasions where the Windows separator (`\`) must be used are documented.
<h4id="question_mark_examples">Question mark examples</h4>
98
122
99
-
**Example 1:** Given the pattern `log?.log` and files:
123
+
**Example 1:** Given the pattern `log?.log`, and the following files:
100
124
```
101
125
log1.log
102
126
log2.log
@@ -110,7 +134,7 @@ log2.log
110
134
log3.log
111
135
```
112
136
113
-
**Example 2:** Given the pattern `image.???` and files:
137
+
**Example 2:** Given the pattern `image.???`, and the following files:
114
138
```
115
139
image.tiff
116
140
image.png
@@ -124,7 +148,7 @@ image.ico
124
148
125
149
<h4id="character_set_examples">Character set examples</h4>
126
150
127
-
**Example 1:** Given the pattern `Sample[AC].dat` and files:
151
+
**Example 1:** Given the pattern `Sample[AC].dat`, and the following files:
128
152
```
129
153
SampleA.dat
130
154
SampleB.dat
@@ -137,7 +161,7 @@ SampleA.dat
137
161
SampleC.dat
138
162
```
139
163
140
-
**Example 2:** Given the pattern `Sample[A-C].dat` and files:
164
+
**Example 2:** Given the pattern `Sample[A-C].dat`, and the following files:
141
165
```
142
166
SampleA.dat
143
167
SampleB.dat
@@ -151,7 +175,7 @@ SampleB.dat
151
175
SampleC.dat
152
176
```
153
177
154
-
**Example 3:** Given the pattern `Sample[A-CEG].dat` and files:
178
+
**Example 3:** Given the pattern `Sample[A-CEG].dat`, and the following files:
155
179
```
156
180
SampleA.dat
157
181
SampleB.dat
@@ -173,28 +197,47 @@ SampleG.dat
173
197
174
198
#### Recursive wildcard examples
175
199
176
-
Given the pattern `**/*.ext` and files:
200
+
Given the pattern `**/*.ext`, and the following files:
177
201
```
178
202
sample1/A.ext
179
203
sample1/B.ext
180
204
sample2/C.ext
181
205
sample2/D.not
182
206
```
207
+
183
208
The pattern would match:
209
+
184
210
```
185
211
sample1/A.ext
186
212
sample1/B.ext
187
213
sample2/C.ext
188
214
```
189
215
216
+
*The following example was generated by Copilot. Copilot is powered by AI, so surprises and mistakes are possible. For more information, see [Copilot general use FAQs](https://aka.ms/copilot-general-use-faqs).*
217
+
218
+
The `**/*.ext` glob pattern is a powerful recursive pattern used in many file systems and tools (like `bash`, `zsh`, `Python glob`, etc.) to match all files ending in `.ext` in the current directory and all subdirectories, no matter how deeply nested.
219
+
220
+
Here are some example paths that would match `**/*.ext`:
221
+
222
+
-`sample1/A.ext`
223
+
-`sample1/B.ext`
224
+
-`sample2/C.ext`
225
+
-`sample2/subdir1/D.ext`
226
+
-`sample2/subdir1/subdir2/E.ext`
227
+
-`sample3/F.ext`
228
+
-`sample3/subdir3/G.ext`
229
+
-`sample3/subdir3/subdir4/H.ext`
230
+
231
+
The `**` part means any number of directories (including zero), and `*.ext` means any file ending in `.ext`.
232
+
190
233
### Exclude pattern examples
191
234
192
-
Given the pattern:
235
+
Given the following pattern, and the following files:
0 commit comments