How to copy folders on same NTFS drive using hardlinks?

Is there a way to create hardlinks to create a duplicate of a folder on the SAME drive (NTFS formatted)? I am looking to do something like this: XCOPY E:\TEMP\SAMPLE1* E:\TEMP\SAMPLE2\ /s but INSTEAD of actually copying the files and using up the extra drive space, just create hardlinks to the files.

Goal: there are only a handful of files that we do not need in the SAMPLE2 folder but want to keep all of them in SAMPLE1. The folder SAMPLE2 will eventually be copied off to another drive.

NOTE: the total content of SAMPLE1 is about 400GB (with multiple sub-folders contained therein) and each of the files that we are going to exclude from SAMPLE2 is about 20-40MB each (there are lots, 100+ files, located in various sub-folders).

So is there a way to do the equivalent of XCOPY (command above) except use hardlinks, and then we go and remove all the files we don't want in SAMPLE2 before copying them off to the external drive; then deleting SAMPLE2 folder.


This is simple in theory. You need to create a symbolic link of the directory(s) which will do EXACTLY what you want. It copies shortcuts that look and act like real files to the user and programs. Then, you can delete the symbolic links you do not want which only deletes the links; then you copy the rest of the "files" (really links) like normal and it will copy the actual files.

But windows is GUI based, and there is no built in GUI solution to make symbolic links. Also, the command prompt made it difficult as well. (If your using Linux, its easy and straight forward via the terminal, and some graphical file managers like GNOME Commander makes it easy through the GUI as well.)

Sooo.. to execute the above solution the "easy" way is to download a plugin and support file (if needed; read download notes) here This will add symbolic link options to your right click menu. The ones you want are "Pick Link Source" to 'copy' the directory, then "Drop As > Hardlink Clone" to paste. Work in the linked directory as you want deleting files (links) and such. Then regular copy and paste it (NOT pick link and drop as) to where ever you want and Voila, shortcuts copied as files!

Finally, delete the linked folder and it's like nothing happened.

The plugin seems to work great. Try it out! Just be careful to make Hard Links ONLY (No soft links or junctions) and be sure to work with the links and not the real files!

Now for those who would mention mklink, here is what I ran into while developing this answer. Using mklink via the command prompt running as an administrator (search for CMD and right click and run as administrator) SHOULD work the same... But it didn't for me (and MANY others if you search). I got an access denied even after modifying privileges via secpol.msc. It seems to be a prevalent problem.


No 3rd-party software needed. This can be accomplished with PowerShell. Here's a pipeline-enabled function that takes a source path ($Path) and a "mirror" path ($MirrorPath). It populates the mirror path with hardlinks to files in the source path and subfolders to match the source subfolders, which are recursively populated as well.

Function Mirror-Path {
  Param(
    [Parameter(Mandatory,ValueFromPipeline,Position=0)]
    [String[]]
    $Path,
    [Parameter(Mandatory,Position=1)]
    [String]
    $MirrorPath
  )
  Begin{
    If ( ! ( Test-Path $MirrorPath )) {
        mkdir $MirrorPath -Force | out-null
    }
  }
  Process{ 
    ForEach ( $Target in $Path ) {
        If ( Test-Path $Target ) {
            Resolve-Path $Target | gci -File | ForEach {
                New-item -ItemType Hardlink -Path $MirrorPath -Name $_.Name -Target $_.FullName | out-null
            }
            Resolve-Path $Target | gci -Directory | ForEach {
                Mirror-Path $_.FullName ( Join-Path $MirrorPath $_.Name )
            }
        }
        Else {
            Echo "'$Target' is not a valid path."
        }
    }
  }
  End {}
}