Thursday, December 11, 2008

Script for automating hardlink creation

::
:: Linking script
:: Usage: ln "source\REGEXP" destination

@echo off
set sourcedir=%1
set destdir=%2
if "%1" == "" goto usage
echo "Linking" %sourcedir% "\*" to %destdir% "\*"

if not exist %destdir% mkdir %destdir%
:: Create the destination directory if it does not exist

:iterate
shift
if "%1" == "" goto end
for %%i in (%sourcedir%) do fsutil hardlink create %destdir%\%%~nxi %%~fi
goto iterate

:usage
color 4f
echo "Usage: ln.bat source-directory\REGEXP destination-directory
echo "If the destination directory does not exist it will be created."
echo "If a fully qualified path is not used, current directory will be used"
pause
color

:end
set sourcedir=

0 comments: