How to Delete a Junction by Using Command Prompt in Windows 7

168,774

Solution 1

Delete junctions with rmdir (rd). Works in all Windows versions.

Solution 2

In my experience fsutil reparsepoint will take care of some cases where rmdir gives Access Denied.

fsutil reparsepoint delete <<PATH>>

Solution 3

Use the -d flag on junction (junction -d ...)

Source: http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx

Share:
168,774

Related videos on Youtube

Nord
Author by

Nord

Updated on September 18, 2022

Comments

  • Nord
    Nord almost 2 years

    I believe in Windows Vista, we could use linkd command. However, I cannot find this command in Windows 7. I know I can use Windows Explorer and delete the junction, but I wonder if this can be done in Command Prompt.

    I can use mklink command to create a junction from a Command Prompt, so, what is the opposite of it (something like linkd)?

  • Nord
    Nord about 13 years
    @gravity, thanks! rd works while del does not.
  • Nord
    Nord about 13 years
    Owh.. I mean @grawity (not @gravity) in my previous comment. Please accept my apology.
  • Jonathon Reinhart
    Jonathon Reinhart over 12 years
    As a Linux user I really struggled to find this. Thanks so much!
  • mejdev
    mejdev almost 12 years
    @JonathonReinhart I resonate well with that. If only Windows started used swap and ext4 without third-party software!
  • user1686
    user1686 almost 12 years
    @Vi3GameHkr: If only Linux started using ntfs without third-party software... /// Windows does use swap, it just calls it "paging file".
  • Adambean
    Adambean almost 11 years
    Thanks :) This works fine. I didn't want to do it in Explorer as it may delete the target stuff too.
  • Aaron Silverman
    Aaron Silverman about 10 years
    For some reason this didn't work for me. I had to do the following in a console with administrator privileges first: fsutil reparsepoint delete C:\Path\To\Junction
  • Brian Low
    Brian Low almost 10 years
    This does not work in Powershell - it will follow the junction and delete all files. Use cmd /c "rmdir mydir".
  • user1686
    user1686 almost 10 years
    @BrianLow: Wat.
  • Brian Low
    Brian Low almost 10 years
  • user2995603
    user2995603 over 7 years
    I had a junction point that was giving access denied if I used rmdir. Using this method, the junction point becomes a regular folder with read-only attribute. attrib -R and rmdir finally finished the job.
  • Sergey
    Sergey over 5 years
    rmdir tells dir is not empty for junction
  • elig
    elig about 4 years
    when the linked directory is invalid rd returned an error but del worked
  • Brian
    Brian almost 4 years
    Absolute legend! was getting "Unspecified Error" or Access Denied" when attempting to delete a stale WindowsApps directory in explorer after much messing around with rmdir, del, and a few other attempts I realised a few contained directories were actually junctions despite having ownership, granting permissions, removing read only attribute, nothing wanted to remove them however your answer worked! Thank you :)
  • Damn Vegetables
    Damn Vegetables over 3 years
    You had to mention that junction is a separate utility that needs to be downloaded.
  • Fizz
    Fizz over 2 years
    This works but it will leave the actual mount point dir behind, as an empty dir. The latter has to be deleted separately.