Skip to content

Commit 54d8bc8

Browse files
Merge pull request #8045 from MicrosoftDocs/users/sdanie/440658
Add recursive example to file matching
2 parents f5c5cfc + 2f4b85b commit 54d8bc8

File tree

1 file changed

+63
-20
lines changed

1 file changed

+63
-20
lines changed

docs/pipelines/tasks/file-matching-patterns.md

Lines changed: 63 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
title: File matching patterns reference
33
description: A reference guide that can help you to understand the file matching patterns for Azure Pipelines and Team Foundation Server (TFS).
44
ms.topic: reference
5+
ai-usage: ai-assisted
56
ms.assetid: 8A92C09C-3EE2-48EF-A2C0-3B2005AACFD7
6-
ms.date: 12/13/2019
7+
ms.date: 06/24/2025
78
monikerRange: '<= azure-devops'
89
---
910

@@ -18,12 +19,19 @@ File and directory names are compared to patterns to include (or sometimes exclu
1819
You can build up complex behavior by stacking multiple patterns.
1920
See [fnmatch](http://man7.org/linux/man-pages/man3/fnmatch.3.html) for a full syntax guide.
2021

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+
2129
### Match characters
2230

2331
Most characters are used as exact matches.
2432
What counts as an "exact" match is platform-dependent:
2533
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.
2735

2836
The following characters have special behavior.
2937

@@ -33,41 +41,57 @@ The following characters have special behavior.
3341
* `**` recursive wildcard. For example, `/hello/**/*` matches all descendants of `/hello`.
3442

3543
### 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
3746
* `*(hello|world)` - zero or more occurrences
3847
* `+(hello|world)` - one or more occurrences
3948
* `@(hello|world)` - exactly once
4049
* `!(hello|world)` - not `hello` or `world`
4150

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.
4353
4454
### Comments
55+
4556
Patterns that begin with `#` are treated as comments.
4657

4758
### Exclude patterns
59+
4860
Leading `!` changes the meaning of an include pattern to exclude.
4961
You can include a pattern, exclude a subset of it, and then re-include a subset of that:
5062
this is known as an "interleaved" pattern.
5163

5264
Multiple `!` flips the meaning. See <a href="#doubleexcl_examples">examples</a>.
5365

54-
You must define an include pattern before an exclude one. See <a href="#character_set_examples">examples</a>.
66+
You must define an include pattern before an exclude pattern. See <a href="#character_set_examples">examples</a>.
5567

5668
### Escaping
69+
70+
5771
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]`.
5872

5973
### Slash
74+
6075
`/` is used as the path separator on Linux and macOS.
6176
Most of the time, Windows agents accept `/`.
6277
Occasions where the Windows separator (`\`) must be used are documented.
6378

6479
## Examples
6580

81+
- [Basic pattern examples](#basic-pattern-examples)
82+
- [Asterisk examples](#asterisk_examples)
83+
- [Question mark examples](#question_mark_examples)
84+
- [Character set examples](#character_set_examples)
85+
- [Recursive wildcard examples](#recursive-wildcard-examples)
86+
- [Exclude pattern examples](#exclude-pattern-examples)
87+
- [Double exclude examples](#doubleexcl_examples)
88+
- [Folder exclude examples](#folder-exclude-examples)
89+
6690
### Basic pattern examples
6791

6892
<h4 id="asterisk_examples">Asterisk examples</h4>
6993

70-
**Example 1:** Given the pattern `*Website.sln` and files:
94+
**Example 1:** Given the pattern `*Website.sln`, and the following files:
7195
```
7296
ConsoleHost.sln
7397
ContosoWebsite.sln
@@ -96,7 +120,7 @@ FabrikamWebsite/FabrikamWebsite.proj
96120

97121
<h4 id="question_mark_examples">Question mark examples</h4>
98122

99-
**Example 1:** Given the pattern `log?.log` and files:
123+
**Example 1:** Given the pattern `log?.log`, and the following files:
100124
```
101125
log1.log
102126
log2.log
@@ -110,7 +134,7 @@ log2.log
110134
log3.log
111135
```
112136

113-
**Example 2:** Given the pattern `image.???` and files:
137+
**Example 2:** Given the pattern `image.???`, and the following files:
114138
```
115139
image.tiff
116140
image.png
@@ -124,7 +148,7 @@ image.ico
124148

125149
<h4 id="character_set_examples">Character set examples</h4>
126150

127-
**Example 1:** Given the pattern `Sample[AC].dat` and files:
151+
**Example 1:** Given the pattern `Sample[AC].dat`, and the following files:
128152
```
129153
SampleA.dat
130154
SampleB.dat
@@ -137,7 +161,7 @@ SampleA.dat
137161
SampleC.dat
138162
```
139163

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:
141165
```
142166
SampleA.dat
143167
SampleB.dat
@@ -151,7 +175,7 @@ SampleB.dat
151175
SampleC.dat
152176
```
153177

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:
155179
```
156180
SampleA.dat
157181
SampleB.dat
@@ -173,28 +197,47 @@ SampleG.dat
173197

174198
#### Recursive wildcard examples
175199

176-
Given the pattern `**/*.ext` and files:
200+
Given the pattern `**/*.ext`, and the following files:
177201
```
178202
sample1/A.ext
179203
sample1/B.ext
180204
sample2/C.ext
181205
sample2/D.not
182206
```
207+
183208
The pattern would match:
209+
184210
```
185211
sample1/A.ext
186212
sample1/B.ext
187213
sample2/C.ext
188214
```
189215

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+
190233
### Exclude pattern examples
191234

192-
Given the pattern:
235+
Given the following pattern, and the following files:
193236
```
194237
*
195238
!*.xml
196239
```
197-
and files:
240+
198241
```
199242
ConsoleHost.exe
200243
ConsoleHost.pdb
@@ -211,15 +254,15 @@ Fabrikam.dll
211254
Fabrikam.pdb
212255
```
213256

214-
<h4 id="doubleexcl_examples">Double exclude</h4>
257+
<h4 id="doubleexcl_examples">Double exclude examples</h4>
215258

216-
Given the pattern:
259+
Given the following pattern, and the following files:
217260
```
218261
*
219262
!*.xml
220263
!!Fabrikam.xml
221264
```
222-
and files:
265+
223266
```
224267
ConsoleHost.exe
225268
ConsoleHost.pdb
@@ -237,14 +280,14 @@ Fabrikam.pdb
237280
Fabrikam.xml
238281
```
239282

240-
<h4 id="doubleexcl_examples">Folder exclude</h4>
283+
#### Folder exclude examples
241284

242-
Given the pattern:
285+
Given the following pattern, and the following files:
243286
```
244287
**
245288
!sample/**
246289
```
247-
and files:
290+
248291
```
249292
ConsoleHost.exe
250293
ConsoleHost.pdb

0 commit comments

Comments
 (0)