Skip to content

Copy-Item with "-Exclude" or/and "-Include" parameters makes it succeed for non-existing source paths #4988

Closed

Description

@amn

Assuming "a" and "b" refer to non-existing filesystem items (CWD is "C:", Windows system NTFS partition), executing Copy-Item a b produces, as expected, an error where Powershell can't find "a":

Copy-Item : Cannot find path 'C:\a' because it does not exist.

Adding the -Exclude c parameter like Copy-Item a b -Exclude c makes, however, the otherwise identical command succeed without errors (checked success with echo $? which returns True). Whether c is an existing item or not is inconsequential here.

I would say this behavior is very unexpected. I expect the second command to fail because source does not exist, irrespective of which paths under the source were to be excluded during copying.

Can anyone comment on this? Am I missing something?

Output of echo $PSVersionTable:

  • PSVersion 5.0.10586.117
  • PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
  • BuildVersion 10.0.10586.117
  • CLRVersion 4.0.30319.42000
  • WSManStackVersion 3.0
  • PSRemotingProtocolVersion 2.3
  • SerializationVersion 1.1.0.1

Windows 7 x86_64 (6.1.7601 Service Pack 1 Build 7601).

Thank you.

Activity

  1. changed the title [-]Copy-Item with "-Exclude" parameter makes it succeed for non-existing source paths[/-] [+]Copy-Item with "-Exclude" or/and "-Include" parameters makes it succeed for non-existing source paths[/+] on Oct 4, 2017
  2. iSazonov commented on Oct 4, 2017

    @iSazonov
    Collaborator

    Armen Michaeli (@amn) Thanks for your report!

    I can repo on PowerShell Core 6.0 Beta.7. For -Include too.

    Michael Klement (@mklement0) Could you please comment?

  3. added
    Issue-Discussion
    on Oct 4, 2017
  4. mklement0 commented on Oct 4, 2017

    @mklement0
    Contributor

    I see the issue too (in PS Core) and it smells like a bug to me as well.

  5. added
    Area-FileSystem-Provider
    WG-Engine-Providers
    and removed on Nov 30, 2021
  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 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.

  8. added
    Resolution-No Activity
    on Nov 16, 2023
  9. 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.

  10. 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-ProviderIssue-DiscussionResolution-No ActivityWG-CmdletsWG-Engine-Providers

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions