Robocopy is a robust file copy command for the Windows command line. It allows users to copy files, directories, and even drives from one location to another. It can be automated with Task Scheduler to run at specific times.
Robocopy example to copy a file from Source to Destination:
Format:
Robocopy [Src] [Dest] [filename] [options]
Src: Can be local or UNC path
Dest: Can be local or UNC path
Code Sample batch file:
SET DTVARYEAR=%Date:~10,4%
SET DTVARMONTH=%Date:~4,2%
SET DTVARDATE=%Date:~7,2%
echo Sync Started
Robocopy C:\Data\TestFolder C:\Data\Logs\TestFolder\%DTVARYEAR%-%DTVARMONTH%-%DTVARDATE%_TestFolder testlogfile.log /FFT /Z /XA:H /LOG+:C:\Data\SchedTasks\LogsTest\%DTVARYEAR%-%DTVARMONTH%_AppLogs.txt
echo Log synced
The above code will copy the testlogfile.log from Source to Destination.
Options:
/FFT Assumes FAT file times (two-second precision).
/Z Copies files in restartable mode.
/XA:H exclude hidden file
/LOG+ log output to file and append.
Additional useful options:
/MIR Mirrors a directory tree (equivalent to /e plus /purge).
/XF exclude specified file
/XD exclude specified directory