Batch Scripting (Windows)


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.


    Usage:

wscript C:\Program files\FreeFileSync\Invisible.vbs C:\MyBatchFile.cmd



"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
)