Last active
August 29, 2015 14:06
-
-
Save yzorg/88d041f0e69f45a967b2 to your computer and use it in GitHub Desktop.
recursive create hardlinks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#CreateHardLinks -source C:\folderD -destination c:\folderC -recurse | |
function CreateHardLinks ($Source, $Destination, [switch]$Recurse) { | |
# Copy of directory structure best handled with `robocopy /E /XF *`, | |
# which will copy directory timestamps. | |
if ($recurse) { | |
robocopy $Source $Destination /E /XF * /DCOPY:T | |
} | |
Get-ChildItem $source -Recurse:$recurse -File | %{ | |
$currFile = $_.Fullname | |
$newLink = $currFile -replace [regex]::Escape($source), $destination | |
#if(!(Test-Path (Split-Path $newLink))) { | |
# #Create missing subfolders | |
# md (Split-Path $newLink) -Verbose | |
#} | |
cmd /c ('mklink /H "{0}" "{1}"' -f $newLink,$currFile) | |
if (!$?) { | |
Write-Warning ("bad command: " + ('mklink /H "{0}" "{1}"' -f $newLink,$currFile)) | |
throw "mklink failed - EXITCODE $LastExitCode - on $currFile" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment