This makes it a very useful simple syncing tool. The following is the script that I use to sync my laptop documents when I’m leaving the office. There are a lot of applications and tools for this but sometimes you just want a portable script.
Please note that this is a one-direction sync. It will not change or remove anything from the source folder.
- Copy and paste the following batch (*.bat) script into your favourite text editor of choice or notepad. (Not Microsoft word) You can also download it directly from here or here mirror. (You might have to right click and select save destination as)
@echo off ::Unicode CHCP 1252 echo %~dp0 ::Remove old log file if exist "%~dp0\robocopylog.txt" del "%~dp0\robocopylog.txt" ::Ignore the following file types. You can add more separated by space set exclude=*.bak *.backup ::Go through each line in the folders.txt file for /f "skip=2 delims=" %%f in ('find /v "" %~dp0\folders.txt') do ( ::Check if the relative path from current directory works if exist "%~dp0\%%f" ( ::Sync relative path robocopy "%%f" "%~dp0\%%f" /v /xf %exclude% /mir /tee /fft /log+:robocopylog.txt ) else ( ::Sync absolute path if relative didnt work robocopy "%%f" "%~dp0\%%~nf" /v /xf %exclude% /mir /tee /fft /log+:robocopylog.txt ) ) ::Wait for keyboard input before closing the window. Remove pause if you want it to close pause
- Save it where you want your backups to be stored (destination). Use whichever name you like. For example robocopy sync unicode folders.bat
- Create a new text file named folders.txt using any text editor and enter each folder that you want to make a backup off separated by a line break. (sources) Save the text file in the same folder as the batch script. Relative paths work too. Example:
- Run the script! The black window will stay open when it’s completed.
With the above example the result would look something like this:
- If source folders share the same name, they will be merged. Keep this in mind.
- This is a one-direction only sync. It will not move or remove anything from the source folder.
- If you don’t want the window to stay open when it’s complete remove the last line “pause” from the script.
- A log file is saved for each operation in robocopylog.txt
- You can add more files to exclude if you want, example:
exclude=*.bak *.backup *.mp4 *.avi