@echo off
setlocal ENABLEDELAYEDEXPANSION
REM %1 = source path ex: "C:\temp"
REM %2 = mount point ex: O:
REM %3 destination Space Name and path "\My Path\My Space"
set programpath=C:\Progra~1\program\program.exe
IF [%1]==[] GOTO :MISSING
IF [%2]==[] GOTO :MISSING
IF [%3]==[] GOTO :MISSING
set source=%1
set mount=%2
set space=%3
SET source=%source:"=%
SET mount=%mount:"=%
SET space=%space:"=%
echo "###########################################################################################"
echo "Starting Migration from %source% to %space%"
echo "###########################################################################################"
REM Find all directories & subdirectories
for /D /R %source% %%i in (*) do call :CREATEDIRS "%source%" "%mount%" "%space%" "%%i"
REM Find all Files
for /R %source% %%i in (*) do call :COPYANDSYNC "%source%" "%mount%" "%space%" "%%i"
echo "##########################################################################################"
echo "Migration from %source% to %space% is complete!"
echo "##########################################################################################"
GOTO :EOF
:CREATEDIRS
set source=%1
set mount=%2
set space=%3
SET copypath=%4
SET source=%source:"=%
SET mount=%mount:"=%
SET space=%space:"=%
SET copypath=%copypath:"=%
SET tocopy=!copypath:%source%=!
REM Create Directories
IF EXIST "%mount%%space%%tocopy%" GOTO :EOF
echo "%date% %time% Creating directory %mount%%space%%tocopy%"
mkdir "%mount%%space%%tocopy%"
GOTO :EOF
:COPYANDSYNC
REM copy and upload
set source=%1
set mount=%2
set space=%3
SET copypath=%4
SET source=%source:"=%
SET mount=%mount:"=%
SET space=%space:"=%
SET copypath=%copypath:"=%
SET tocopy=!copypath:%source%=!
IF EXIST "%mount%%space%%tocopy%" GOTO :EOF
echo "%date% %time% Copying %source%%tocopy% to %mount%%space%%tocopy%"
echo n | copy /-y /v /b /z "%source%%tocopy%" "%mount%%space%%tocopy%" >nul
echo "%date% %time% Done Copying %source%%tocopy% to %mount%%space%%tocopy"
set reversepath=%space%%tocopy%
set reversepath=%reversepath:\=/%
echo "%date% %time% Synchronizing %reversepath% ... (Check Sync Monitor for Progress)"
"%programpath%" --sync -n "%reversepath%" -r 0 | find /I "sync"
call :CHECKUPLOAD
GOTO :EOF
:CHECKUPLOAD
set "result="
set searchstring=%tocopy: =.%
set searchstring=%searchstring:\=.%
set searchstring=%searchstring:"=%
FOR /F "tokens=*" %%A IN ('%programpath% --retrievesynclist ^| findstr "%searchstring%" ^| findstr "State.:.[0-5]"') DO SET result=%%A
IF NOT "%result%"=="" GOTO :FILESUPLOADING
echo "%date% %time% Done Synching %space%%tocopy%
GOTO :EOF
:FILESUPLOADING
REM echo Files are still being uploaded!
ping -n 2 127.0.0.1>nul
GOTO :CHECKUPLOAD
:MISSING
echo You need to enter a Source path for the first parameter ex: "C:\temp"
echo You need to enter the mount drive for the second parameter ex: O:
echo You need to enter a destination path for the destination ex: "\My Space\My Path"
echo ex: migration.bat "C:\temp" O: "\My Space\My Path"
exit /b
:CLEARCACHE
set clearspacepath=%1
set reverseclearspacepath=%clearspacepath:\=/%
"%programpath%" --clearcache -n "%reverseclearspacepath%" -r 1