Repository navigation
Closed
Labels
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-FixedThe issue is fixed.The issue is fixed.WG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.built-in PowerShell providers such as FileSystem, Certificates, Registry, etc.
Description
Steps to reproduce
In File Explorer on an NTFS volume, create the file: [abc].txt
Following this run:
ls '[abc].txt'Expected behavior
Directory: C:\Users\Dave
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2019-05-06 12:07 AM 0 [abc].txt
Actual behavior
No output displayed.
Environment data
Name Value
---- -----
PSVersion 6.2.0
PSEdition Core
GitCommitId 6.2.0
OS Microsoft Windows 10.0.17763
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Additional Cases and Information
The file name can be displayed using tab completion, but the brackets are preceded by back ticks, which indicates that Windows can see the file and assumes that the brackets are special characters. When attempting to list the file using the ls command, the following error is generated:
ls : Cannot find path 'C:\Users\Dave\`[abc`].txt' because it does not exist.
At line:1 char:1
+ ls '.\`[abc`].txt'
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Users\Dave\`[abc`].txt:String) [Get-ChildItem], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
Other commands generate no output or errors as well.
Get-FileHash '[abc].txt'
# Generates no output
1 | Out-File '[abc].txt'
# Generates error stating that the wildcard path did not resolve to a fileAccording to Microsoft's "About Quoting Rules" page, "When you enclose a string in single-quotation marks (a single-quoted string), the string is passed to the command exactly as you type it. No substitution is performed".
Metadata
Metadata
Assignees
Labels
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-FixedThe issue is fixed.The issue is fixed.WG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.built-in PowerShell providers such as FileSystem, Certificates, Registry, etc.
Activity
iSazonov commentedon May 6, 2019
/cc kwkam Michael Klement (@mklement0)
kwkam commentedon May 6, 2019
Short:
#9257 resolves this issue.
Long:
Most cmdlets that accept a path treats the first string parameter as
-Path, which can do wildcard/glob. The commandls '[abc].txt'is the same as
where
[abc].txtwill be considered as a wildcard pattern which matches eithera.txt/b.txt/c.txt, so we have to:-LiteralPathto indicate that the path is literal:However, the first solution still does not work because the
Get-ChildItemcmdlet is not handling the-Pathargument correctly, when it contains escaped special character:Get-ChildItemcheck if glob should be performed on-PathWhich means it will try to find a file literally named
`[abc`].txtinstead of[abc].txtiSazonov commentedon May 6, 2019
kwkam Thanks for great comment! Should we add new test in #9257 related the issue?
mklement0 commentedon May 6, 2019
And the related issues re file-creating cmdlets such as
Out-File(and operator>) are #4726 and #9475. Related: #9225.