

@echo off

rem
rem 1  absolute source directory
rem 2  file name (a directory)
rem 3  absolute installation directory
rem 4  exclusion file
rem

set source_dir=%1%
set dir_name=%2%
set install_dir=%3%
set exclusion_file=%4%

set dest_file_path=%install_dir%\%dir_name%
set ref_file=%dest_file_path%.cmtref
set full_source_name=%source_dir%\%dir_name%

if "%source_dir%"=="" exit /B 0
if "%dir_name%"=="" exit /B 0
if "%install_dir%"=="" exit /B 0

if NOT exist "%full_source_name%" exit /B 0

if NOT exist %install_dir% mkdir %install_dir%

if NOT exist %install_dir% echo "Cannot install directory %dir_name%, no installation directory specified" & exit /B 0

echo Installing directory %dir_name% into %install_dir%

if exist %dest_file_path% rmdir /S/Q %dest_file_path%

if exist %ref_file% del %ref_file%

mkdir %dest_file_path% 
xcopy /S/Y/Q/EXCLUDE:%exclude_file% %full_source_name% %dest_file_path%
echo %full_source_name% >%ref_file%
