Monday, December 12, 2011

Windows 7 Symlinks

I'm finally realizing (maybe the last person to cotton on to this), that starting with Windows Vista, we now have the capability to create Unix-style symlinks between Windows files and folders. YIPPEE!

It's done with the mklink command (from the cmd window):

mklink
Creates a symbolic link.

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

        /D      Creates a directory symbolic link.  Default is a file
                symbolic link.
        /H      Creates a hard link instead of a symbolic link.
        /J      Creates a Directory Junction.
        Link    specifies the new symbolic link name.
        Target  specifies the path (relative or absolute) that the new link
                refers to.

In my particular case, I'm experimenting with the Sencha Touch mobile application development kit. Creating the simple "Hello World" app as a place to start. This requires that Sencha SDK. I downloaded that and would prefer not to create a copy of it in my app server. Symlinks to the rescue. Since my Hello World app makes reference to the SDK as  <script src="lib/touch/sencha-touch.js" type="text/javascript"/> , I simply created a lib directory in my app folder and then made a symlink to the Sencha Touch folder:

mkdir lib
cd lib
mklink /D touch ..\..\sencha

And voila - no copying.

Worth noting - to remove the link, use a regular delete: DEL or RMDIR depending.