Skip to content

Move-Item produces an unexpected error when using -Include/-Exclude/-Filter #2385

Closed

Description

Move-Item's -Include, -Exclude, and -Filter parameters produce errors when they should not.

Steps to reproduce

Include:

New-Item -Name "foo.txt" -ItemType File
New-Item -Name "bar.txt" -ItemType File
Move-Item -Path ".\*" -Destination "move.txt" -Include "bar*"

Exclude:

New-Item -Name "foo.txt" -ItemType File
New-Item -Name "bar.txt" -ItemType File
Move-Item -Path ".\*" -Destination "move.txt" -Exclude "bar*"

Filter:

New-Item -Name "foo.txt" -ItemType File
New-Item -Name "bar.txt" -ItemType File
Move-Item -Path ".\*" -Destination "move.txt" -Filter "bar*"

Expected behavior

Include:
No error.
bar.txt should not exist anymore and there should be a new file named move.txt with the contents of bar.txt.

Exclude:
No error.
foo.txt should not exist anymore and there should be a new file named move.txt with the contents of foo.txt.

Filter:
No error.
bar.txt should not exist anymore and there should be a new file named move.txt with the contents of bar.txt.

Actual behavior

Include:
Successfully moves bar.txt to move.txt, but produces the following errors.

PS F:\test> Move-Item -Path .\* -Destination move.txt -Include "bar*"
Move-Item : Cannot move item because the item at 'F:\test\foo.txt' does not exist.
At line:1 char:1
+ Move-Item -Path .\* -Destination move.txt -Include "bar*"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Move-Item], PSInvalidOperationException
    + FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.MoveItemCommand

Exclude:
Successfully moves foo.txt to move.txt, but produces the following errors.

PS F:\test> Move-Item -Path .\* -Destination move.txt -Exclude "bar*"
Move-Item : Cannot move item because the item at 'F:\test\bar.txt' does not exist.
At line:1 char:1
+ Move-Item -Path .\* -Destination move.txt -Exclude "bar*"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Move-Item], PSInvalidOperationException
    + FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.MoveItemCommand

Filter:
Successfully moves bar.txt to move.txt, but produces the following errors.

PS F:\test> Move-Item -Path .\* -Destination move.txt -Filter "bar*"
Move-Item : Cannot create a file when that file already exists
At line:1 char:1
+ Move-Item -Path .\* -Destination move.txt -Filter "bar*"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (F:\test\foo.txt:FileInfo) [Move-Item], IOException
    + FullyQualifiedErrorId : MoveFileInfoItemIOError,Microsoft.PowerShell.Commands.MoveItemCommand

Environment data

PS F:\test> $PSVersionTable
Name                           Value
----                           -----
PSRemotingProtocolVersion      2.3
BuildVersion                   3.0.0.0
WSManStackVersion              3.0
SerializationVersion           1.1.0.1
PSVersion                      6.0.0-alpha
GitCommitId                    v6.0.0-alpha.10
CLRVersion
PSEdition                      Core
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}

Activity

  1. added this to the milestone on Oct 25, 2016
  2. modified the milestones: , on May 25, 2017
  3. jeffbi commented on May 29, 2017

    @jeffbi

    Joey Aiello (@joeyaiello) Can you please assign this one to me?

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

Metadata

Metadata

Assignees

Labels

Resolution-FixedWG-Cmdlets

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions