Click here to Skip to main content
Click here to Skip to main content

HardLinks - Manage your library of common classes

, 5 Mar 2004
Rate this:
Please Sign up or sign in to vote.
A tool for managing NTFS hard links

Sample Image - HardLinks.jpg

Introduction

I have some classes that I reuse in many projects. I wanted a way to share these files between projects, while always updating a "master" copy that is the latest version. The NTFS support for hard links seems to be an answer. I can now keep all the master files in one directory, and link to the files I want to use from individual projects.

Background

NTFS hard links allow a file to appear in more than one directory with more than one name. Unix users will be familiar with this concept.

Because this can get very confusing very quickly, I have assumed some rules.

Rules

  • Real files are stored in just a couple or so directories. I use "C:\dev\Common" and "C:\dev\Common\Icons".
  • Link files are stored in a separate directory to the rest of the project files. I use "<project>\Common" and "<project>\Icons".
  • Link file names are the same as the real file names.

Using the code

  • First, create your real file directory using Explorer.
  • Add your common files to this directory using Explorer. I have included the file Cursors.cs from my WaitCursor article to get you started.
  • Create your link directory using Visual Studio. In Solution Explorer, right-click your project and select "Add/New Folder". Name it "Common".
  • Fire up the HardLinks exe. Click the Add Directory button ( Open File icon ).
  • Set your real and link directories in the dialog and press ok.

You should now have your real and link file directories selected in the list boxes on the left, and the Cursors.cs file in the checked list box on the right.

  • Check Cursors.cs to create a link file. If you look at your link file directory with Explorer, you will see the Cursors.cs file. We know that this is really a link, not a separate file.
  • Go back to Visual Studio and right-click your Common folder in your project. Select "Add/Add Existing Item" and pick the Cursors.cs file.

You now have the link to the real file in your project.

This may seem a bit complicated, but it gets easier as you add more common files.

Points of Interest

The checked list box on the right lists all the files in the selected real directory. The check state indicates the files in the link directory.

You can see the Legend from the context menu, but here are the states and their meanings :

  • Unchecked : No file exists
  • Indeterminate : File exists, but is a real file not a link
  • Checked : Link exists.

Be careful not to delete real files!

This applies to icon files especially, as Visual Studio overwrites them when you edit them, instead of just updating their contents. If you have to edit an icon file, then manually select the file in your real file directory, or you will just make a copy in your link file directory which is what we're trying to avoid.

The code is not very interesting. It is mostly GUI stuff, but I have included it in case you want to modify it.

WinDiff

I have included this app in the zip files. It is an optional install with Visual Studio - under C++ Tools I seem to remember.

Point to the exe in the Options, or just put the exe in the application directory and you can immediately compare the currently selected real and link file directories.

Acknowledgements

I used the Magic Docking Library by Phil Wright. It made life very easy, so I give it a 5.

History

  • Version 1 : 2004 March 6 : First version.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Nicholas Butler

United Kingdom United Kingdom

I built my first computer, a Sinclair ZX80, on my 11th birthday in 1980.
In 1992, I completed my Computer Science degree and built my first PC.
I discovered C# and .NET 1.0 Beta 1 in late 2000 and loved them immediately.
I have been writing concurrent software professionally, using multi-processor machines, since 1995.
 
In real life, I have spent 3 years travelling abroad,
I have held a UK Private Pilots Licence for 20 years,
and I am a PADI Divemaster.
 
I now live near idyllic Bournemouth in England.
 
If you would like help with multithreading, please contact me via my website:
 
 
I can work 'virtually' anywhere!

Comments and Discussions

 
Generalmuch more easier way... PinmemberVlad Tepes6-Mar-04 7:40 
GeneralRe: much more easier way... PinmemberNicholas Butler6-Mar-04 19:08 
GeneralRe: much more easier way... Pinmemberrromerot8-Mar-04 1:48 
GeneralFor reference PinmemberNorm Almond6-Mar-04 6:14 
GeneralRe: For reference PinmemberNicholas Butler6-Mar-04 19:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140718.1 | Last Updated 6 Mar 2004
Article Copyright 2004 by Nicholas Butler
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid