RSS RSS Subscribe

Moving Directories In Windows — Using Junctions

By , September 20, 2009 18:45
Hot:

How many times have you discovered that your hard disk is filling up even though you are not installing any applications.  You think ‘do I really have that much data’, or you store your data on a separate drive from your OS and applications (something we recommend to all clients and friends) and cannot understand why your OS or application drive keeps filling up.

Chances are its because of the applications themselves either downloading content into it’s application directory, or it uses the windows ‘Application Data’ directory to store temporary or cached data, some cases even permanent data remains in these directories.

A good example of this is Google Earth that keeps it’s cache database in your Apps Data directory, and can easily exceed several gigabytes in size.

Or maybe you love the convenience of the “My Documents” directory and accessing it directly from the start menu, but don’t have enough room for your data.

Symbolic links are simply a means to link a object to another.  The concept was that if you needed a file or a directory in a couple locations, rather than copying it making two identical copies (and two sources of confusion) you could create a link to a ‘spacekeeper’ in one place to the real file in the other location.  It was also very handy to create virtual drives, and some other neat filesystem tricks.

Symbolic links have been around for a long time for unix/linux/BSD users, and I could speculate that Windows 2000′s POSIX engine was the driving force behind this.  Regardless in Windows the lack of symbolic links pre W2K was a big missing part of the filesystem.  Symbolic linking may have existed in Windows since Windows 2000 Pro, but it has not been directly supported in the OS until Vista.  When Windows 2000 Pro was released the ability to ‘code’ symbolic links appeared, but no userland way to perform these operations (no command or program to run to do this, but you could write one…).  With Vista there is now a tool included with the OS so it’s ready to go.  For 2000 or XP users there is a tool you can download to do this.

Well there are several means to solve this problem, some are simple and some require downloading some extra tools to help.  I’ll discuss these options for you, but lets start with a simple solution, and work up to using symbolic links.

Re-Targetting your personal directories.

Some directories can easily be ‘Retargeted’ to a different location which works great with ‘My Documents’ and those types of directories.  However it’s not perfect since the original directory still exists, many poorly written programs will ignore the new target and still use the old one.  But regardless this method works fine for you and me, and most importantly the start menu will not see any diffferences.

So, if you want to retarget your “My Documents” directory, it’s a simple operation:

1. Click on “Start”
2. Right-click on “My Documents” and select properties.
3. This opens the Properties Window, and you can see the Target: that is currently being used.
4. Click on “Find Target” and navigate to the folder you wish to move this directory to
5. Or you can just enter the name in the Target: location
6. Once this is done, click on “Move”, this will then open the move wizard and prompt you through the retarget process.
7. Click “Ok” when done.
8. If you decide you don’t like this, you simply click on “Restore Defaults” to put everything back where it was originally.  Again you’ll have to click “Move” to move the folders contents as opposed to just retargetting the directory.

That’s it.  (We’ll check under vista and see how it works.)

Vista is ready to go

Now, lets say your directory doesn’t support retargetting, like nearly all of them.  What do you do?  Well if you have Vista you don’t have to download anything.  To perform this we will create a symbolic link to the new location using the tool mklink.  To use this tool you are going to have to use the Command Line, and in our example we are going to create a link to our new directory so:

1. Click on “Start”
2. Select “Run”
3. type “cmd” in the window
4. When the Command Line opens up at the prompt

mklink /d “c:\original directory” “d:\new directory”

Note: I use the double quotes to indicate that if the directory has a space in it, these can be used to encapsulate the parameter.  Even if you don’t have any spaces in your directory names, this will still work fine.  Now mklink will create a link to “d:\new directory” for “c:\original directory”.  Now anytime we use the former it will happily work, except we will be actually using new location instead.

Windows 2000 or XP?  Just a download away

Nothing was provided by default in Windows 2000 or XP versions to allow you to use symbolic links, however many varieties are available.  One simple tool is available for download from microsofts web site called junction.  This tool works very similar to Vista’s mklink except we have to download it and install it manually.  This is really easy:

1. To download go to http://technet.microsoft.com/en-ca/sysinternals/bb896768.aspx
2. Download ths zip file to your desktop
3. Unzip the files onto your desktop.  At time of writing there were only the EULA.txt and the main executable.
4. Move the files to your C:\Windows directory this way the command will be in the normal search path, and its a good place to keep your windows tools.
5. Now you can use it.  So, using the same example as above we would type:

junction “c:\original directory” “d:\new directory”

And again we have the same solution.  No parameters are required.

For additional information on these tools here are the links I used:

Junction:
http://technet.microsoft.com/en-ca/sysinternals/bb896768.aspx

Notes about links and using junctions, this is old, but the warnings about DELETING files that are linked should be read and understood
http://support.microsoft.com/?kbid=205524

Mklink:
http://technet.microsoft.com/en-us/library/cc753194.aspx

And if you liked this, but would rather do this from your desktop simply right click and go, try this out:
http://schinagl.priv.at/nt/hardlinkshellext/hardlinkshellext.html


related post

FacebookTwitterRedditGoogle BookmarksGoogle ReaderYahoo MailSlashdotWordPressDiggIdenti.caYahoo BuzzStumbleUponMySpaceLinkedInDeliciousLiveJournalMSDNHotmailAsk.com MyStuffBlogger PostBookmark/FavoritesOrkutShare

Comments are closed

Theme by Themocracy