Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ChrisUbben opened this issue Sep 29, 2016 · 1 comment
Closed
Assignees
Labels
Resolution-Fixed The issue is fixed. WG-Cmdlets general cmdlet issues
Milestone

Comments

@ChrisUbben
Copy link

ChrisUbben commented Sep 29, 2016

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...}
@ChrisUbben ChrisUbben added the WG-Cmdlets general cmdlet issues label Sep 29, 2016
@SteveL-MSFT SteveL-MSFT added this to the 6.0.0 milestone Oct 25, 2016
@joeyaiello joeyaiello modified the milestones: 6.0.0-HighPriority, 6.0.0 May 25, 2017
@jeffbi
Copy link
Contributor

jeffbi commented May 29, 2017

@joeyaiello Can you please assign this one to me?

TravisEz13 pushed a commit that referenced this issue Jun 23, 2017
…rs (#3878)

* Make Move-Item work with its -Include, -Exclude, and -Filter parameters (#2385)

Invoke the correct overload of SessionState.Path.GetResolvedPSPathFromPSPath, passing the cmdlet context object.

* Update tests per code review.

* Changes per code review.

* Remove stray comment
@iSazonov iSazonov added the Resolution-Fixed The issue is fixed. label Jun 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution-Fixed The issue is fixed. WG-Cmdlets general cmdlet issues
Projects
None yet
Development

No branches or pull requests

5 participants