Environment Variables for Windows' Built-in Libraries?
Does Windows 7 define environment variables for pre-existing Libraries? I am curious because I often use these when typing a path in Open/Save dialogs or from the Run
prompt. For example, to get to the current user's Firefox settings directory, run
:
%APPDATA%\Mozilla\Firefox
It's a handy shortcut, and I was hoping to find something similar for library paths. For example:
%LIBRARIES%\Music\
%MUSIC%\
I understand that libraries aggregate one-or-more top-level folders, so there could be ambiguity. Microsoft has a list of environment variables, but most are not accessible via the Windows UI. This question also links to a nice list, but does not include a user's Documents
folder, Music
folder, etc.
Windows Libraries are in fact just xml
files which define how to display a collection of folders. They are displayed using a special shell extension which is built in to Windows. Since they are not real folders, files and sub-folders cannot be accessed directly via a path.
With an open explorer window, you can type in the address bar:
libraries\music
This does not seem to work from the File Name
box of open/save dialogs. Nor does it work with the run
command.
What you can do about it:
Windows Vista introduced the "Known Folders" concept. It replaces the older "constant special item ID list" (CSIDL) methodology used in XP. There is an excellent post on the Windows Blog; it discusses this change and provides an overview of the *.library-ms
file structure.
Known Folders have GUIDs. To access them via command line, prefix your URI with knownfolder:
. There are dozens defined. To access the current user's Music
folder for example, run
the following command:
knownfolder:{4BD8D571-6D19-48D3-BE97-422220080E43}
This will get you to the pre-defined default music folder. So, if you have changed the library's folder, this will unfortunately not work.
A library's default folder can be accessed programmatically by using IShellLibrary interface, but that is out of the scope of my original question. It seems that the best approach is to either:
- Manually map enviroment variables to their known path
- Or manually map environment variables using their GUID. The advantage here is that you make it a system variable and have it work for all users).
If you want %music%
to point to your music folder then you just add a new environmental variable to your system.
If you want to %Libraries%
point to your libraries then make a shortcut on c:\
, for example, and then create a new environmental variable pointing to your c:\libraries
shortcut. (but entering directly into sub-folders will not work, but you can create a new variable for those that are in Libraries)
You can then call them both from run with %music%
or %Libraries%