user1513171
user1513171

Reputation: 1974

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!

Upvotes: 27

Views: 79563

Answers (5)

Mark Robinson
Mark Robinson

Reputation: 19

I had this error. Two things I did to fix it.

  1. check I was actually in the directory I thought I was and not another one with a very similar path.
  2. put quotes around the new link name.

First attempt: mklink /d \shared_files ....\my-app-public\src\shared_files gave error described.

Second attempt: mklink /d “.\shared_files” ....\my-app-public\src\shared_files worked fine.

Upvotes: 0

user10840272
user10840272

Reputation: 1

I had the same issue. You have to make sure the Source folder does not already exist. (if it does , then rename it to something else)

In case of below Backup folder should not exist under MobileSync. Since Apple iTunes looks for Backup folder with that name, just rename the existing folder to something like OriginalBackup to avoid iTunes from finding it. Instead the mklink will synonym Backup to D: folder as below

mklink /J C:\Users\Dell\Apple\MobileSync\Backup D:\Apple\Backup\iPhoneXRBackup

Upvotes: 0

TerryMcK
TerryMcK

Reputation: 1

I did this for Google Picasa so I could access photographs on more than one machine. It works very well as Picasa is not really a netowrk enabled program. For me I did the following:

  • Install Picasa
  • Run the application. This will create all the necessary database files.
  • Close the application.
  • Navigate to the directory where the database is - on Windows 7 it will be created in c:\users\\AppData\Local\Google
  • There will be two folders Picasa2 and Picasa2Albums Copy these folders to a network location. In my case I created a folder called o:\PicasaDatabase and copyied these folders into it.
  • Next rename the original folders to Picasa2.old and Picasa2Albums.old

Run the following commands from an elevated cmd prompt:

mklink /D "c:\Users\\AppData\Local\Google\Picasa2" "o:\PicasaDatabase\Picasa2"

mklink /D "c:\Users\\AppData\Local\Google\Picasa2Albums" "o:\PicasaDatabase\Picasa2Albums"

Two symbolic links will have been created in the source location and they will point to the network drive.

Obviously using symbolic links like this is a workaround for application that are not networkable and only one user can access the database at once.

Upvotes: 0

bajov
bajov

Reputation: 211

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`
    

Upvotes: 21

Jay
Jay

Reputation: 4686

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.

Upvotes: 43

Related Questions