Open Source, 100% Compatible ln for Windows (and Junction Point library)

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.

Binaries for Windows x86 and x64

ln-win Source Code on GitHub

11 thoughts on “Open Source, 100% Compatible ln for Windows (and Junction Point library)

  1. @neosmart: neat! just tried it out, works great. And the source code is clean, thanks!

    @randomcore: doesn’t look like Hermann’s tool is open source. And it doesn’t use the same syntax as the unix ln, either.

  2. As a sysadmin, I always get frustrated when I forget the order of commandline arguments for mklink. This is awesome!

    Thanks :)

  3. someone: that’s correct. If there’s enough demand, we’ll make it work on XP in “backwards-compatibility mode,” i.e. hardlinks only for both files and folders.

  4. Thanks for this! I never could remember the name of the Windows one, let alone it’s syntax.

  5. Thanks for the write,I myself like and support open source but this is my first time encountering In-win and mklink. Another new discovery for me.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>