We’ve been huge fans of symlinks for forever, and even posted about Windows Vista’s new mklink commandline utility with quite the passion back in 2006 when the ability to create soft-links from the commandline was first added to Windows.
However, there are a few things that have forever irked us about the ln lookalike called mklink.exe:
- It’s called mklink and not ln. (I mean, you just get can’t get around that fact)
- The arguments are switched around. `mklink something_doesnt_exist actual_file` is just…….. wrong!
- By default, mklink will create softlinks and not hardlinks. ln requires the /h flag to create a hardlink.
- mklink isn’t smart enough to distinguish between files and folders. You need explicitly tell it via the commandline.
- Even then, mklink has two different switches depending on the type of directory link you want. /D for softlink’d directories, and /J for hardlink’d directories.
- mklink can’t be used outside of cmd.exe (such as in PowerShell). (Hat tip: Jason)
- And, of course, mklink isn’t open source.
So we made our own.
ln-win is available in 32-bit and 64-bit, uses the same syntax, names, switches, and argument ordering as ln on *nix. And pursuant to our promise to contribute more to open source, ln-win and our Junction Point library is 100% open source, freely licensed under the generous terms of the MIT license.
Perhaps more importantly, ln-win contains an open source Junction Point library. While Win32 APIs exist to create symlinks (on Vista and up), there is no API for creating hardlinks of any kind (for files or folders). The NeoSmart JunctionPoint library provides the following APIs:
bool CreateJunctionPoint(LPCTSTR origin, LPCTSTR junction); bool IsDirectoryJunction(LPCTSTR path); bool GetJunctionDestination(LPCTSTR path, OUT LPTSTR destination); bool DeleteJunctionPoint(LPCTSTR path);
As you can see, the NeoSmart JunctionPoint library provides all the APIs you need both to create and interact with hardlinks. IsDirectoryJunction can be used for both symlinks and hardlinks, making it a snap to make your code symlink/hardlink aware, letting you intelligently avoid cyclic paths and data duplication for any filesystem traversal needs.