Most IT pros will probably agree that there are features within Windows that feel incomplete, or that have been poorly designed. Even so, there are also things within Windows that Microsoft has really gotten right. One really minor feature that I have always found to work well is the ability to use libraries. I’m sure most of you are well familiar with the concept of libraries within Windows, but for the benefit of any novices out there, the libraries provide easy access to a file system path without the end user needing to know what that path is. The Documents library, for example, appears in the Libraries container in File Explorer, but actually points to C:\Users\<user name>\ Documents. An administrator also has the ability to redirect the Documents library (and other libraries) to a network location. This allows users to save their work to a familiar location while the data is actually being written to a location of the administrator’s choosing. Having the ability to redirect a folder to a location of your choosing can be very useful, and there are two different ways in which you can perform your own custom folder redirections. One option is to create a custom library. I will give you a brief rundown of that technique in a moment. The other technique involves using a command line utility to literally redirect one folder to another.
Creating custom libraries
To create a custom library, begin the process by opening File Explorer. Now, right-click on the Libraries folder and then right-click within the empty space beneath the list of libraries (in the main portion of File Explorer, not in the console tree). Next, select the New | Library commands from the shortcut menu. This will cause Windows to create a brand new library. You can stick to using the default name of New Library if you wish, but I recommend using a name that is a bit more descriptive.
Now, right-click on the library that you just created, and choose the Properties command from the shortcut menu. This will take you to a screen that is similar to what you see below.
As you can see, the new library is initially empty. To link the library to a folder, click on the Add button and then select the folder that you want to include in the library, and click the Include Folder button. Incidentally, a single library can be based on multiple folders, so some people use libraries as a tool for aggregating data.
Performing folder redirections without libraries
Libraries are great, but they do have their limitations. For starters, it can be a little bit tricky to include a network path in a library (indexing usually has to be enabled on the server). Another limitation is that when you create a library, you are essentially creating a shortcut to a different folder (or set of folders). You aren’t redirecting an existing folder of your choice to a new location. If you want to perform true folder redirections without the confines of a library, you can use a command line tool called MKLINK.
Suppose for a moment that a particular application has been hardcoded to save its output to C:\Data, but that for whatever reason you needed the data to be saved elsewhere. By using MKLINK, you could redirect the folder to a different folder, or even to a different drive.
The MKLINK utility can create three different types of links. For folder redirections to another location on the same computer, you will need to use a junction link. Fortunately, the syntax couldn’t be easier. Just append the /J parameter, and the source and target locations. Let me give you an example.
For this example, I’ve got a folder named C:\MyData and I want to redirect it to D:\Data. Here is the command used for doing so.
Mklink /J C:\MyData D:\Data
You can see an example of this in the figure below.
You would use exactly the same syntax if you wanted to redirect a folder to a different folder on the same drive. If, for example, you wanted to redirect C:\MyData to C:\Data then you would use this command:
Mklink /J C:\MyData C:\Data
Before I move on, there are a couple of things that you need to know about using this command. First, the MKLINK command will only work properly if you run it from an elevated command prompt. Second, the source folders cannot exist ahead of time. MKLINK creates the source folder for you. Conversely, it is up to you to create the destination folder. In case you are wondering, deleting the source folder (C:\MyData in this case) does not delete the destination folder (D:\Data) or its contents.
To see what the redirection looks like in action, check out the figure below. Here you can see that I copied a file named nano.vhd to C:\MyData. However, the file has been placed in d:\data.
Interestingly enough, if I use the DIR command, Windows shows the redirected folder as being of type <JUNCTION> rather than being type <DIR> as it normally would be. You can see what this looks like below.
The folder type has changed to indicate that a junction is in use.
You can also use MKLINK to redirect a local folder to a network location, by using a UNC path or a mapped drive letter. The difference is that you cannot use a junction link. Instead, you will have to use a symbolic link, which is sometimes called a soft link. The syntax is basically the same, except that the command uses /D instead of /J.
Unfortunately, Windows is smart enough to realize that the symbolic link points to a network location, so you can’t use this technique to trick the OS into indexing a network location that it would otherwise be unable to index.
A great alternative to libraries
As handy as libraries can be, they aren’t well suited to every situation. Folder redirections by way of the MKLINK command is a great alternative to libraries.