Skip to content

Remove-Item and Move-Item don't support escape characters in wildcard patterns on Unix #3725

Closed

Description

Note:

Wildcard patterns- at least in the context of Get-Item - support ` as the escape character to represent literal ` instances in a path and to escape the following metacharacters: * ? [ ]

Remove-Item and Move-Item currently do not support that, neither with -Path nor with -Include.

Steps to reproduce

# Create a file that contains a literal backtick and a literal substring that would be a valid
# sub-pattern if interpreted as a wildcard expression.
New-Item -Type File 'a`[b]'

# Match the newly created file using a wildcard expression with suitable escaping.
Remove-Item * -Include 'a```[b`]'  -WhatIf
Remove-Item -Path 'a```[b`]' -WhatIf

Move-Item * -Include 'a```[b`]' /tmp -WhatIf
Move-Item -Path 'a```[b`]' /tmp -WhatIf

Expected behavior

Both commands in each pair should find the target file and output information about how it would be deleted / moved.

Actual behavior

All commands unexpectedly fail to find the file:

Remove-Item : An object at the specified path /Users/jdoe/a`[b] does not exist.
...

Curiously, the error message quotes the correct literal path that it claims doesn't exist.

Move-Item's symptoms differ:

Move-Item : Cannot move item because the item at '...' does not exist.
...
Move-Item : The specified wildcard character pattern is not valid: a\[b

Curiously, all existing files in the directory (even those that don't match the pattern) are reported as non-existent.

Environment data

PowerShell Core v6.0.0-alpha (v6.0.0-alpha.18) on macOS 10.12.4
PowerShell Core v6.0.0-alpha (v6.0.0-alpha.18) on Ubuntu 16.04

Activity

  1. iSazonov commented on May 8, 2017

    @iSazonov
    Collaborator

    Is Move-Item affected too?

  2. changed the title [-]Remove-Item doesn't support escape characters in wildcard patterns on Unix[/-] [+]Remove-Item and Move-Item don't support escape characters in wildcard patterns on Unix[/+] on May 8, 2017
  3. mklement0 commented on May 8, 2017

    @mklement0
    ContributorAuthor

    Ilya (@iSazonov): Good point; yes, Move-Item is affected too - I've retitled and revised the original post accordingly.

  4. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  5. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  6. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  7. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-FileSystem-Providerspecific to the FileSystem providerIssue-BugIssue has been identified as a bug in the productOS-LinuxOS-macOSResolution-No ActivityIssue has had no activity for 6 months or moreWG-Cmdletsgeneral cmdlet issuesWG-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