Skip to content

Commit d3d1f64

Browse files
authored
Filesystem wildcards work differently than for strings (#11107)
1 parent 0480795 commit d3d1f64

File tree

4 files changed

+84
-24
lines changed

4 files changed

+84
-24
lines changed

reference/5.1/Microsoft.PowerShell.Core/About/about_Wildcards.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes how to use wildcard characters in PowerShell.
33
Locale: en-US
4-
ms.date: 12/16/2022
4+
ms.date: 05/14/2024
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_wildcards?view=powershell-5.1&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about Wildcards
@@ -30,16 +30,19 @@ In this case, the asterisk (`*`) wildcard character represents any characters
3030
that appear before the `.ppt` file name extension.
3131

3232
Wildcard expressions are simpler than regular expressions. For more
33-
information, see [about_Regular_Expressions](./about_Regular_Expressions.md).
33+
information, see [about_Regular_Expressions][01].
3434

3535
PowerShell supports the following wildcard characters:
3636

3737
- `*` - Match zero or more characters
3838
- `a*` matches `aA`, `ag`, and `Apple`
3939
- `a*` doesn't match `banana`
40-
- `?` - Match one character in that position
40+
- `?` - For strings, match one character in that position
4141
- `?n` matches `an`, `in`, and `on`
4242
- `?n` doesn't match `ran`
43+
- `?` - For files and directories, match zero or one character in that position
44+
- `?.txt` matches `a.txt` and `b.txt`
45+
- `?.txt` doesn't match `ab.txt`
4346
- `[ ]` - Match a range of characters
4447
- `[a-l]ook` matches `book`, `cook`, and `look`
4548
- `[a-l]ook` doesn't match `took`
@@ -58,6 +61,11 @@ through **l**, type:
5861
Get-ChildItem C:\Techdocs\[a-l]*.txt
5962
```
6063

64+
> [!NOTE]
65+
> Wildcard matching for filesystem items works differently than for strings.
66+
> For more information, see the _Remarks_ section of the
67+
> [DirectoryInfo.GetFiles(String, EnumerationOptions)][05] method.
68+
6169
There may be cases where you want to match the literal character rather than
6270
treat it as a wildcard character. In those cases you can use the backtick
6371
(`` ` ``) character to escape the wildcard character so that it is compared
@@ -93,6 +101,13 @@ foreach ($point in $p) {
93101

94102
## See also
95103

96-
- [about_If](about_If.md)
97-
- [about_Language_Keywords](about_Language_Keywords.md)
98-
- [about_Script_Blocks](about_Script_Blocks.md)
104+
- [about_If][02]
105+
- [about_Language_Keywords][03]
106+
- [about_Script_Blocks][04]
107+
108+
<!-- link references -->
109+
[01]: ./about_Regular_Expressions.md
110+
[02]: about_If.md
111+
[03]: about_Language_Keywords.md
112+
[04]: about_Script_Blocks.md
113+
[05]: xref:System.IO.DirectoryInfo.GetFiles*#system-io-directoryinfo-getfiles(system-string-system-io-enumerationoptions)

reference/7.2/Microsoft.PowerShell.Core/About/about_Wildcards.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes how to use wildcard characters in PowerShell.
33
Locale: en-US
4-
ms.date: 12/16/2022
4+
ms.date: 05/14/2024
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_wildcards?view=powershell-7.2&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about Wildcards
@@ -30,16 +30,19 @@ In this case, the asterisk (`*`) wildcard character represents any characters
3030
that appear before the `.ppt` file name extension.
3131

3232
Wildcard expressions are simpler than regular expressions. For more
33-
information, see [about_Regular_Expressions](./about_Regular_Expressions.md).
33+
information, see [about_Regular_Expressions][01].
3434

3535
PowerShell supports the following wildcard characters:
3636

3737
- `*` - Match zero or more characters
3838
- `a*` matches `aA`, `ag`, and `Apple`
3939
- `a*` doesn't match `banana`
40-
- `?` - Match one character in that position
40+
- `?` - For strings, match one character in that position
4141
- `?n` matches `an`, `in`, and `on`
4242
- `?n` doesn't match `ran`
43+
- `?` - For files and directories, match zero or one character in that position
44+
- `?.txt` matches `a.txt` and `b.txt`
45+
- `?.txt` doesn't match `ab.txt`
4346
- `[ ]` - Match a range of characters
4447
- `[a-l]ook` matches `book`, `cook`, and `look`
4548
- `[a-l]ook` doesn't match `took`
@@ -58,6 +61,11 @@ through **l**, type:
5861
Get-ChildItem C:\Techdocs\[a-l]*.txt
5962
```
6063

64+
> [!NOTE]
65+
> Wildcard matching for filesystem items works differently than for strings.
66+
> For more information, see the _Remarks_ section of the
67+
> [DirectoryInfo.GetFiles(String, EnumerationOptions)][05] method.
68+
6169
There may be cases where you want to match the literal character rather than
6270
treat it as a wildcard character. In those cases you can use the backtick
6371
(`` ` ``) character to escape the wildcard character so that it is compared
@@ -93,6 +101,13 @@ foreach ($point in $p) {
93101

94102
## See also
95103

96-
- [about_If](about_If.md)
97-
- [about_Language_Keywords](about_Language_Keywords.md)
98-
- [about_Script_Blocks](about_Script_Blocks.md)
104+
- [about_If][02]
105+
- [about_Language_Keywords][03]
106+
- [about_Script_Blocks][04]
107+
108+
<!-- link references -->
109+
[01]: ./about_Regular_Expressions.md
110+
[02]: about_If.md
111+
[03]: about_Language_Keywords.md
112+
[04]: about_Script_Blocks.md
113+
[05]: xref:System.IO.DirectoryInfo.GetFiles*#system-io-directoryinfo-getfiles(system-string-system-io-enumerationoptions)

reference/7.4/Microsoft.PowerShell.Core/About/about_Wildcards.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes how to use wildcard characters in PowerShell.
33
Locale: en-US
4-
ms.date: 12/16/2022
4+
ms.date: 05/14/2024
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_wildcards?view=powershell-7.4&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about Wildcards
@@ -30,16 +30,19 @@ In this case, the asterisk (`*`) wildcard character represents any characters
3030
that appear before the `.ppt` file name extension.
3131

3232
Wildcard expressions are simpler than regular expressions. For more
33-
information, see [about_Regular_Expressions](./about_Regular_Expressions.md).
33+
information, see [about_Regular_Expressions][01].
3434

3535
PowerShell supports the following wildcard characters:
3636

3737
- `*` - Match zero or more characters
3838
- `a*` matches `aA`, `ag`, and `Apple`
3939
- `a*` doesn't match `banana`
40-
- `?` - Match one character in that position
40+
- `?` - For strings, match one character in that position
4141
- `?n` matches `an`, `in`, and `on`
4242
- `?n` doesn't match `ran`
43+
- `?` - For files and directories, match zero or one character in that position
44+
- `?.txt` matches `a.txt` and `b.txt`
45+
- `?.txt` doesn't match `ab.txt`
4346
- `[ ]` - Match a range of characters
4447
- `[a-l]ook` matches `book`, `cook`, and `look`
4548
- `[a-l]ook` doesn't match `took`
@@ -58,6 +61,11 @@ through **l**, type:
5861
Get-ChildItem C:\Techdocs\[a-l]*.txt
5962
```
6063

64+
> [!NOTE]
65+
> Wildcard matching for filesystem items works differently than for strings.
66+
> For more information, see the _Remarks_ section of the
67+
> [DirectoryInfo.GetFiles(String, EnumerationOptions)][05] method.
68+
6169
There may be cases where you want to match the literal character rather than
6270
treat it as a wildcard character. In those cases you can use the backtick
6371
(`` ` ``) character to escape the wildcard character so that it is compared
@@ -93,6 +101,13 @@ foreach ($point in $p) {
93101

94102
## See also
95103

96-
- [about_If](about_If.md)
97-
- [about_Language_Keywords](about_Language_Keywords.md)
98-
- [about_Script_Blocks](about_Script_Blocks.md)
104+
- [about_If][02]
105+
- [about_Language_Keywords][03]
106+
- [about_Script_Blocks][04]
107+
108+
<!-- link references -->
109+
[01]: ./about_Regular_Expressions.md
110+
[02]: about_If.md
111+
[03]: about_Language_Keywords.md
112+
[04]: about_Script_Blocks.md
113+
[05]: xref:System.IO.DirectoryInfo.GetFiles*#system-io-directoryinfo-getfiles(system-string-system-io-enumerationoptions)

reference/7.5/Microsoft.PowerShell.Core/About/about_Wildcards.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes how to use wildcard characters in PowerShell.
33
Locale: en-US
4-
ms.date: 12/16/2022
4+
ms.date: 05/14/2024
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_wildcards?view=powershell-7.5&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about Wildcards
@@ -30,16 +30,19 @@ In this case, the asterisk (`*`) wildcard character represents any characters
3030
that appear before the `.ppt` file name extension.
3131

3232
Wildcard expressions are simpler than regular expressions. For more
33-
information, see [about_Regular_Expressions](./about_Regular_Expressions.md).
33+
information, see [about_Regular_Expressions][01].
3434

3535
PowerShell supports the following wildcard characters:
3636

3737
- `*` - Match zero or more characters
3838
- `a*` matches `aA`, `ag`, and `Apple`
3939
- `a*` doesn't match `banana`
40-
- `?` - Match one character in that position
40+
- `?` - For strings, match one character in that position
4141
- `?n` matches `an`, `in`, and `on`
4242
- `?n` doesn't match `ran`
43+
- `?` - For files and directories, match zero or one character in that position
44+
- `?.txt` matches `a.txt` and `b.txt`
45+
- `?.txt` doesn't match `ab.txt`
4346
- `[ ]` - Match a range of characters
4447
- `[a-l]ook` matches `book`, `cook`, and `look`
4548
- `[a-l]ook` doesn't match `took`
@@ -58,6 +61,11 @@ through **l**, type:
5861
Get-ChildItem C:\Techdocs\[a-l]*.txt
5962
```
6063

64+
> [!NOTE]
65+
> Wildcard matching for filesystem items works differently than for strings.
66+
> For more information, see the _Remarks_ section of the
67+
> [DirectoryInfo.GetFiles(String, EnumerationOptions)][05] method.
68+
6169
There may be cases where you want to match the literal character rather than
6270
treat it as a wildcard character. In those cases you can use the backtick
6371
(`` ` ``) character to escape the wildcard character so that it is compared
@@ -93,6 +101,13 @@ foreach ($point in $p) {
93101

94102
## See also
95103

96-
- [about_If](about_If.md)
97-
- [about_Language_Keywords](about_Language_Keywords.md)
98-
- [about_Script_Blocks](about_Script_Blocks.md)
104+
- [about_If][02]
105+
- [about_Language_Keywords][03]
106+
- [about_Script_Blocks][04]
107+
108+
<!-- link references -->
109+
[01]: ./about_Regular_Expressions.md
110+
[02]: about_If.md
111+
[03]: about_Language_Keywords.md
112+
[04]: about_Script_Blocks.md
113+
[05]: xref:System.IO.DirectoryInfo.GetFiles*#system-io-directoryinfo-getfiles(system-string-system-io-enumerationoptions)

0 commit comments

Comments
 (0)