In order to facilitate using FreeFileSync and RealtimeSync in advanced synchronization scenarios, creating batch files is a good way to provide additional functionality. The following section will give some general hints and examples for custom *.cmd and *.bat files.
When
starting a batch file from RealtimeSync make synchronous calls to
FreeFileSync only. This will prevent RealtimeSync continue detecting
changes while synchronization is still in progress.
During execution of a Windows Batch file (*.bat/*.cmd) a black console window is shown. You can hide it using the Visual Basic script "RunSilent.vbs" located in FreeFileSync's installation directory.
Usage:
wscript C:\Program
files\FreeFileSync\Invisible.vbs C:\MyBatchFile.cmd
FreeFileSync returns with an Errorlevel below zero if unresolved problems remain:
"C:\Program
Files\FreeFileSync\FreeFileSync.exe"
"H:\Silent_Config.ffs_batch"
if not errorlevel 0
(
::if
something went wrong, add special treatment here
echo
Errors occurred during synchronization...
pause
)
Example: Shutdown PC after synchronization
::start
FreeFileSync Batch
Job
"C:\Users\ZenJu\Desktop\SyncJob.ffs_batch"
::schedule
shutdown after 10 seconds
shutdown
/s /t 10
Example: A simple locking facility – (Note: FreeFileSync already has a more powerful directory locking mechanism implemented that allows multiple writers in parallel)
:tryAgain
if
not exist \\share\folder\lock (
::create
the lock
echo
This is a lock file > \\share\folder\lock
::execute
the synchronization batch job synchronously
"C:\Program
Files\FreeFileSync\FreeFileSync.exe"
"C:\MySyncJob.ffs_batch"
del
\\share\folder\lock
) else (
::wait
5 seconds then try starting sync again:
choice
/C:AB /T:5 /D:A > NUL
goto tryAgain
)