How to use Junction if you want Symbolic links in Windows XP

Ever since I started developing using Unix machines I've wanted symbolic links in Windows XP.  A recent pursuit of backup solutions left me really wanting symbolic links so I started the search.  This blog post gave me everything I needed, using a tool from Microsoft's website called junction.

This command line tool created junction points between a symbolic name and a real folder on your hard drive (sorry network drives cannot be linked to).

I downloaded it and placed the junction.exe file in my C:\WINDOWS\system32 directory so it would be on my system path.

Below is my little walk-through of how to use junction.

I created a folder on my desktop called "junction test" and created a folder inside that called "folder":


I created a text file called "README.txt" inside the "folder" directory:


I opened a Windows DOS prompt (cmd) and navigated to the "junction test" folder on my desktop, then I ran the junction command like this:
junction "junction" folder

This gave the following output:
Junction v1.05 - Windows junction creator and reparse point viewer

Copyright (C) 2000-2007 Mark Russinovich

Systems Internals - http://www.sysinternals.com


Created: C:\Documents and Settings\abeacock\Desktop\junction test\junction

Targetted at: C:\Documents and Settings\abeacock\Desktop\junction test\folder

And the folder now looked like this:


If I double-clicked on the "junction" folder this is what I saw:


So as you can see the contents of the "folder" directory is now available in via the "junction" directory as well.  Obviously the junction doesn't need to be next to the folder you want to link too (that would be of little use) but it can be anywhere on your harddrive (I was using it to point into my DropBox sync folder).

WARNING ABOUT JUNCTION

Only the junction tool knows that these folders are actually symbolic links, the rest of the Windows file system thinks they are normal folders. So for example you can simply delete the junctions via Windows and they go in your recycle bin and the folder that it points to stays where it was:

 

But if you then empty your recycle bin it also empties the contents of the folder that this junction was pointing at (which is probably NOT what you wanted to happen!):


So please remember to always use the junction command to create & delete junctions, you can also use it to show you which directories are actually junctions so you know if you should delete it or not, refer to the junction download page for more details.

It's a fantastic tool for Windows XP and very very handy for certain things but please bear in mind the warning above...

Technorati Tags: , , ,

4 comments:

Anonymous said...

Thanks.

abhay said...

thanx man for this useful tutorial post.its so helpful.

Keyman said...

Thank you for the post! I tried it on local level, and it worked perfectly. I also tried it on network level to link my iPad backup folder in C: to my network drive Z: , to free up disc space in local C: drive, but didn't have any luck. Does junction.exe work on network drives in Windows XP, or does it work only on local drives?

Anonymous said...

Thank you for your post. I had problem using this on XP, your explanation on the use cleared it and I'm able to now get it to work.

I was having problem in that you can not create the joint folder first through win explorer, you have to do it at the command line and then tell it the target.

Jim B. from the US