PowerShell: Move-Item trying to create directory even though directory had already existed
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
- have a folder nested in one anther with the same name and be in the parent directory
- 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)
We should check HResult -2147024713 (800700B7) here: https://github.com/PowerShell/PowerShell/blob/618d1a7c78f0702156d5ba1cd1be31df6d7f54d7/src/System.Management.Automation/namespaces/FileSystemProvider.cs#L6120-L6122