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.
1 Answer
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 TargetNote:
mklinkcreates the link sodir2should 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 dir2Followed by:
mklink /d dir2 dir1Or:
mklink /j dir2 dir1Now 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\fileYou have to do this for every new file added to dir2.
Further Reading
- An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
- mklink - Create a symbolic link to a directory or a file, or create a hard file link or directory junction.
- rd - Delete folder(s).