- Saturday, March 24, 2007
Perhaps the best new "feature" of Windows Vista is the Unix-inspired re-organization of user home directories. That is, instead of placing user-specific files under the abhorrent
Documents and Settingsdirectory, each user's folder resides under the command-line-friendly
Usersdirectory in the root system drive. Even better, your music is no longer considered a document. It's hard to argue against the fact that
C:\Users\Derek\Musicis cleaner than
C:\Documents and Settings\Derek\My Documents\My Music(or in some cases, the 8.3 friendly
I use Vista on a couple of my computers, and I've grown to appreciate the new folder structure. Gone are the days of hacking together your own home directory structures just to try and cope with the unfriendly madness (who hasn't created a folder or two under
C:\just to make them typable?). Unfortunately, I still use several machines running XP, so it's hard to rely on this sane structure -- leading to grotesque hacks such as functions called
.emacsfile (I wish I were kidding).
There are some additional advantages to utilizing the built-in home directory structure rather than creating your own. For example, the Run dialog resolves path reference relative to your home directory. So, if you type
Start -> Run -> ., your home directory will open. Sub-folders can be accessed just as easily -- typing
Start -> Run -> dev\blogopens my blog source tree. Also, many tools (backup, indexing, etc.) will only consider content in your actual profile directory (the one that Windows knows about).
Another nice benefit is that the compact path structure is Cygwin-friendly, so you can safely set your
HOMEenvironment variable (also used by Emacs, of course). Thus,
~/Desktopin Cygwin matches
~\Desktopin Powershell. I keep my
HOMEdirectory synced across many machines (Vista, XP, and Linux) using Subversion, and it's nice being able to keep everything in the same place.
Fortunately, we can make some relatively simple tweaks to our XP systems to make the structure more closely resemble that of our Vista and Unix friends.
Junction, Junction, What's your Function?
Chances are you've been running your operating system for a while, and you've got a bunch of clutter under your
Documents and Settingsfolder. More importantly, you probably have a bunch of applications with stored absolute paths under that folder, not to mention all of those common dialog pointers. So obviously, just renaming the
Documents and Settingsfolder is going to cause more problems than it'll solve.
If XP had symlinks (another feature added in Vista), of course, we'd have an easy solution. We could simply type
ln -s DOCUME~1 Users, and we'd be off to a good start. We could update environment variables to use our new path structure, and we wouldn't break the old path references. Fortunately, XP does support directory symlinks ... well, sort of. XP's default file system, NTFS, supports something called a "junction point". For our needs, it'll do.
While junctions are supported by NTFS, there is no built-in tool for creating them. Enter Junction, a simple command line tool for creating (and viewing targets of) NTFS junction points. With the tool located in your PATH, run the following command sequence to create the link:
C:\Documents and Settings\Derek>cd \ C:\>junction Users "Documents and Settings" Junction v1.04 - Windows junction creator and reparse point viewer Copyright (C) 2000-2005 Mark Russinovich Systems Internals - http://www.sysinternals.com Created: C:\Users Targetted at: C:\Documents and Settings
At this point, we can access our home directory under the
Userspath, but unfortunately Windows has no idea that we've actually intended to change our home directory. For example, starting a fresh command line session stills shows that old, annoying
Documents and Settingspath.
To fix this, we need to dig into the registry. Under
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList, there should be a number of keys in the form
S-x-x-xx-.... Browse through the keys until you find the one with a
ProfileImagePathvalue ending with your user name (e.g.
%SystemDrive%\Documents and Settings\Derek). Change this value to use the new path (e.g.
%SystemDrive%\Users\Derek). You will need to restart Windows for it to pick up the change.
After rebooting, you should default to the new
Userspath when starting a fresh console session. And because it's actually a junction point, all of your existing files should be right there with you. This is a nice start, but there are still some annoyances:
My Documentsshould be
My Music(and its similarly named friends) should also drop the silly "My" prefix, and ascend one directory (unless you think music is a document, of course).
Again, junction points are exactly what we need. Use the following command sequence to set them up:
C:\Users\Derek>junction Documents "My Documents" ... C:\Users\Derek>for %f in (Music Pictures Videos) do junction %f "My Documents\My %f" ...
You might also want to hide the
My Documentsfolder, so you don't see two references to the same folder when browsing your home directory. You could just make it hidden, but if you're like me you have hidden folder display enabled. In this case, we just need to make it hidden and give it the system attribute using the following command:
attrib +S +H "My Documents".
Our paths are now much prettier, but we do get stuck with the ugly default folder icon. Fortunately, you can right click on the folder whose icon you wish to update, click Properties, and change the icon in the Customize tab (you must do this before the next step, where they are assigned as special folders). I use the normal icons in
Documentsand the like. For my root home directory (
Derek), I use
user-home.ico(attached to this post) from the Tango Desktop Project. The icon was conveniently translated to ICO format by Ben Brown. You might receive a warning about "enabling task folders", this is safe to ignore.
As with the
Usersjunction point, we need to tell Windows about our new paths. For this, we'll use a Microsoft tool called Tweak UI. Install the tool, start it (
Start -> Run -> tweakui), and select the
Special Foldersitem under
My Computerin the tree control. Here you can select each path for which we created a junction, and assign the new path.
We've solved our ugly path problem, but overall usability still leaves something to be desired. For example, our common dialogs all have direct pointers to our
Documentsfolder, but it's still rather painful to get to our root home directory to, say, open a music file.
Fortunately, Tweak UI comes in handy here as well. Under
Common Dialogs, select
Places Bar, and choose
Custom Places Bar. Here, you can define up to five paths that you will have easy access to using the common file dialog used by most Windows applications.
Here's the new dialog in action:
Another nice convenience is having a home directory link in your start menu, as below (simply drag the link there to create the shortcut):