PowerShell: Move-Item trying to create directory even though directory had already existed

Prerequisites

Steps to reproduce

  1. have a folder nested in one anther with the same name and be in the parent directory
  2. run PS > mv -Path ./drakensang\drakensang -Destination .\

Expected behavior

PS > mv -Path ./drakensang\drakensang -Destination .\
job sucessfully completes with the contents of ./drakensang\drakensang in .\drakensang

Actual behavior

PS > mv  -Path ./drakensang\drakensang -Destination ./
Move-Item: Cannot create 'C:\Users\solomon\winget-pkgs\manifests\b\Bigpoint\drakensang' because a file or directory with the same name already exists.

Error details

Exception             :
    Type       : System.IO.IOException
    TargetSite :
        Name          : MoveDirectory
        DeclaringType : System.IO.FileSystem, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral,
PublicKeyToken=7cec85d7bea7798e
        MemberType    : Method
        Module        : System.Private.CoreLib.dll
    Message    : Cannot create 'C:\Users\solomon\winget-pkgs\manifests\b\Bigpoint\drakensang' because a file or
directory with the same name already exists.
    Source     : System.Private.CoreLib
    HResult    : -2147024713
    StackTrace :
   at System.IO.FileSystem.MoveDirectory(String sourceFullPath, String destFullPath, Boolean isCaseSensitiveRename)
   at System.IO.FileSystem.MoveDirectory(String sourceFullPath, String destFullPath)
   at System.IO.DirectoryInfo.MoveTo(String destDirName)
   at Microsoft.PowerShell.Commands.FileSystemProvider.MoveDirectoryInfoUnchecked(DirectoryInfo directory, String
destinationPath, Boolean force)
   at Microsoft.PowerShell.Commands.FileSystemProvider.MoveDirectoryInfoItem(DirectoryInfo directory, String
destination, Boolean force)
TargetObject          : C:\Users\solomon\winget-pkgs\manifests\b\Bigpoint\drakensang\drakensang
CategoryInfo          : WriteError: (C:\Users\solomon\wi…akensang\drakensang:DirectoryInfo) [Move-Item], IOException
FullyQualifiedErrorId : MoveDirectoryItemIOError,Microsoft.PowerShell.Commands.MoveItemCommand
InvocationInfo        :
    MyCommand        : Move-Item
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 28
    Line             : mv  -Path ./drakensang\drakensang -Destination ./
    PositionMessage  : At line:1 char:1
                       + mv  -Path ./drakensang\drakensang -Destination ./
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : mv
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :

Environment data

Name                           Value
----                           -----
PSVersion                      7.3.0-preview.7
PSEdition                      Core
GitCommitId                    7.3.0-preview.7
OS                             Microsoft Windows 10.0.19044
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 17 (4 by maintainers)

Most upvoted comments