How often have you wanted to have access to the same file from two or more directories (folders)? Of course, it has always been possible to do so via a desktop shortcut (
.LNK) file, and those are good as far as they go, but they hide important information, such as when the file to which they point was last updated.
Frequently, I create a file in one directory, such as the notes associated with an active development project. However, I often need access to the same file from other locations, such as the notes directory associated with a library upon which the project depends. When such a case arose a while ago, I took the opportunity to apply my recently acquired knowledge about how symbolic links work in Windows.
Recent Windows versions, starting with Vista, I believe, include
mklink.exe a command line system utility similar to
fsutil.exe, which predates it by several Windows iterations. Unlike
mklink.exe, the links created by
fsutil.exe break when you save an update, leaving copies of the old version in place of each of is hard links.
Using the code
Do the following.
- Use the File Explorer (Windows Explorer) to navigate to the directory where you created the original file.
- Select (highlight) the original file.
- Use the Copy Path tool on the Home tab to deposit a copy of the fully-qualified file name onto the Windows Clipboard. Since the File Explorer always quotes this string, it is guaranteed to work in a command.
- Navigate to the directory where you want to create the symbolic link.
cmd into the address bar, and press the Enter key. This creates a command prompt window with its working directory set to the directory in the active File Explorer window.
- Enter the following command to create your symbolic link.
mklink [SymLinkName] [AbsoluteSourceFileName]
In the above command:
SymLinkName is the name by which the link will be known in the destination directory. Enter a name and extension, but omit any path.
AbsoluteSourceFileName is the absolute (fully qualified) path to the original file. This is the text that you copied into the clipboard in step 3. Hit Ctrl-V to paste it into the command window.
Following is an example that creates a symbolic link,
Default_Event_Source_ID_Missing.TXT, in directory
F:\Source_Code\Visual_Studio\Projects\WizardWrx_Libs\WizardWrx_NET_API\_NOTES 2019/07/15 11:46:02.34>mklink Default_Event_Source_ID_Missing.TXT F:\Source_Code\Visual_Studio\Projects\GUI_Apps\CountDownClock\NOTES\Default_Event_Source_ID_Missing.TXT
symbolic link created for Default_Event_Source_ID_Missing.TXT <&kt;<===>> F:\Source_Code\Visual_Studio\Projects\GUI_Apps\CountDownClock\NOTES\Default_Event_Source_ID_Missing.TXT
Points of Interest
Though the syntax of
fsutil.exe are almost idetical,
mklink.exe works in any command prompt windows, while
fsutil.exe needs an elevated prompt. Save the elevator for when you need it.
Monday, 15 July 2019 is the publication date.
Tuesday, 16 July 2019, while reviewing changes made by an editor, of which I was just notified by email, it came to my attention that there were a few formatting and typographical errors that escaped my notice yesterday.
Wednesday, 17 July 2019, while reviewing my own changes after they were posted, I found another typographical error, and took the opportunity to clarify that File Explorer is another name for Windows Explorer.