Skip to content

On Unix, PowerShell will not find files with backslashes in their names #3666

@jeffbi

Description

@jeffbi

This is similar to #3414, but involves only the backslash portion.

The basis of the problem is premature normalization of paths. Path normalization happens quite early (and very frequently and in a great number of places in the PowerShell code) while processing a command. Usually this happens before the path reaches its provider, and often that normalization is a brute-force change one slash to another mechanism. Thus a path such as 1\2 on Unix is "normalized" to 1/2, ensuring that the path will never be found.

Using -LiteralPath does not prevent the path normalization, so that is not a workaround.

Steps to reproduce

From bash:

$ touch 'a\b'

then from PowerShell:

PS> Remove-Item a\b

or

PS> Move-Item a\b a-b

Expected behavior

The file a\b is deleted

Actual behavior

Remove-Item : Cannot find path 'a/b' because it does not exist.
At line:1 char:1
+ Remove-Item a\b
+ ~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (a/b:String) 
    [Remove-Item], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand

Environment data

> $PSVersionTable
Name                           Value                                                     
----                           -----                                                     
BuildVersion                   3.0.0.0                                                   
CLRVersion                                                                               
GitCommitId                    v6.0.0-alpha.18-38-g08e855556cff42274a5903799b826e78d0c...
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                   
PSEdition                      Core                                                      
PSRemotingProtocolVersion      2.3                                                       
PSVersion                      6.0.0-alpha                                               
SerializationVersion           1.1.0.1                                                   
WSManStackVersion              3.0                                                       

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-FileSystem-Providerspecific to the FileSystem providerIssue-BugIssue has been identified as a bug in the productResolution-No ActivityIssue has had no activity for 6 months or moreWG-Cmdlets-Managementcmdlets in the Microsoft.PowerShell.Management moduleWG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions