Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows 7 Symbolic Link - Cannot create a file when that file already exists

I'm trying to create a symbolic link between two directories. I have a directory called TestDocs and TestDocs2. I will be doing all my work in TestDocs, but I need it all to be reflected in TestDocs2. So all files that are in TestDocs2 will be replicated in TestDocs, and if I add a file, change a file, etc in TestDocs it should be reflected in TestDocs2.

So I thought it would be as simple as just doing this:

mklink /D TestDocs TestDocs2

But when I do that I get the error:

Cannot create a file when that file already exists

Why am I getting this?

Also, do I have the order of my TestDocs and TestDocs2 wrong in the command?

Thanks for the help, Symbolic Links have always confused me!

like image 669
user1513171 Avatar asked Aug 20 '12 12:08

user1513171


People also ask

Can not create a file when that file already exists?

Press Windows key + R to open up a Run dialog box. Then, type ms-settings:windowsupdate and press Enter to open up the Windows Update tab inside the Settings app. Run dialog: ms-settings:windowsupdate. Inside the Windows Update screen, click on Check for updates and install every available pending update.

Can't create a file when that file already exists Mklink?

This is because you're trying to fake the existence of the Backup folder (so it must not exist already), but you also need its parents to exist. Windows will hence create a hard link shortcut Backup on the C:\ drive.

How do I fix a file already exists?

The error message "File Already Exists" or "File Already in Use" indicates that a file CTI Navigator Desktop is attempting to use is already open, locked or corrupted. The fix is to replace a corrupted file, and close, unlock or replace a locked file.

How do I remove a symbolic link in Windows?

To delete a symbolic link, treat it like any other directory or file. If you created a symbolic link using the command shown above, move to the root directory since it is "\Docs" and use the rmdir command. If you created a symbolic link (<SYMLINK>) of a file, to delete a symbolic link use the del command.


2 Answers

The correct usage is:

MKLINK [options] {link} {target}

You're creating a link, so the link is the new link you're about to create.
And the target is the link's target, which is the existing directory.

like image 121
Jay Avatar answered Oct 19 '22 16:10

Jay


Here is how that worked for me. I wanted to relocate my C:\ProgramData\Package Cache to F: partition.

Steps I had to do:

  1. Physically move "C:\ProgramData\Package Cache" to F:. Now I had "F:\ProgramData\Package Cache" and "C:\ProgramData\Package Cache" is gone since I moved it.

  2. In cmd run (all in one line, split here for readability)

    mklink /J "C:\ProgramData\Package Cache" 
              "F:\ProgramData\Package Cache"
    
  3. Result:

    Junction created for C:\ProgramData\Package Cache <<===>> 
                         F:\ProgramData\Package Cache`
    
like image 37
bajov Avatar answered Oct 19 '22 15:10

bajov