-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
The 1st positional argument passed to Get-ChildItem binds to -Path, meaning that wildcard expressions are supported.
However, values that are literal paths - values that do not contain wildcard metacharacters such as * - should be treated as such.
-
Without
-Recurse, that is already the case: A nonexistent literal path triggers an error. -
With
-Recurse:- The nonexistent path (assuming that it is a mere filename or its parent path exists) is treated like a wildcard expression that happens to match nothing.
- Additionally, this matching is apparently performed in all the directories in the subtree.
Workaround (and generally the better choice if you know a path to be a literal one):
Get-ChildItem -Recurse -LiteralPath <path>
Update: Get-ChildItem -Recurse <name> may also yield false positives, by matching <name> anywhere in the subtree rather than just in the current location - see below.
Steps to reproduce
Get-ChildItem NoSuch
Get-ChildItem NoSuch -RecurseExpected behavior
Both commands should report an error re nonexistent item NoSuch.
Actual behavior
Get-ChildItem NoSuch -Recurse produces no output at all (neither success nor error), and $? is set to $True.
Environment data
PowerShell Core v6.0.0-rc.2 (v6.0.0-rc.2) on Microsoft Windows 7 Enterprise (64-bit; v6.1.7601)
Windows PowerShell v5.1.14409.1012 on Microsoft Windows 7 Enterprise (64-bit; v6.1.7601)