0

I have a directory 'dir1' with some files in it and a directory 'dir2' where I'll add some files. How can I create a link/junction (or just connect them)? I tried "mklink /D (or /J) dir1 dir2" but apparently it's not working and if it would I think that dir1 would just be dir2. I want dir1 to have the files it has now and when I add files to dir2 to show up in dir1.

0

I tried mklink /D (or /J) dir1 dir2

I have a directory 'dir1' with some files in it and a directory 'dir2' where I'll add some files.

You have the directories the wrong way around. You also need to remove dir2 before creating the link.

The syntax for mklink is:

MKLINK [[/D] | [/H] | [/J]] Link Target

Note:

  • mklink creates the link so dir2 should not exist before you run the command.

In your case dir2 will be the new link and dir1 will be the target, so you need to use:

rd dir2

Followed by:

mklink /d dir2 dir1

Or:

mklink /j dir2 dir1

Now dir2 has the files of dir1 (In other words dir2 is dir1). I don't want that.

That's what directory links are designed to do.

You need to rethink.

One option is to add the files to dir2 and then when in dir1 create symbolic link to the files in dir2. You can do this with:

cd dir1
mklink file \full\path\to\dir2\file

You have to do this for every new file added to dir2.


Further Reading

  • Yeah but now dir2 has the files of dir1 (In other words dir2 is dir1). I don't want that – JohnGRThess Jul 5 '16 at 17:16
  • @JohnGRThess That's what directory links are designed to do. You need to rethink. One option is to add the files to dir2 and then when in dir1 create links to the files in dir2. You can do this with mklink file \full\path\to\dir2\file. You have to do this for every new file added to dir2. Answer updated. – DavidPostill Jul 5 '16 at 19:39

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.