question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:13

github_iconTop GitHub Comments

0reactions
euamotubainacommented, Jan 6, 2023

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)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found