Move-Item trying to create directory even though directory had already existed
See original GitHub issuePrerequisites
- 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
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:13
Top Results From Across the Web
Powershell 'Move-Item' doesn't make directory if it ...
I've tried Move-Item -Force $from $to , but that didn't help out. What can I do to make sure Powershell creates the needed...
Read more >Cannot create a file when that file already exists.
Hello,. I currently have a PS script that trims files names and renames them. Here is the script that works well. Powershell.
Read more >Move-Item (Microsoft.PowerShell.Management)
The Move-Item cmdlet moves an item, including its properties, contents, ... The missing directory is not created for you, even if you use...
Read more >Solved: Move-Item cmdlet doesn't force the move
Powershell isn't case-sensitive but I even tried to change the -Force to ... Move-Item : Cannot create a file when that file already...
Read more >createDirectory(atPath:withIntermediateDirectories ...
Creates a directory with given attributes at the specified path. ... is set and the directory already exists, or false if an error...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
We should check HResult -2147024713 (800700B7) here: https://github.com/PowerShell/PowerShell/blob/618d1a7c78f0702156d5ba1cd1be31df6d7f54d7/src/System.Management.Automation/namespaces/FileSystemProvider.cs#L6120-L6122
Some of my older scripts that relied on Move-Item to merge some directories stopped working after I updated to 7.3. I’m pretty sure they used to work fine until around 7.2.7 (I used them for the last time around Nov 22)