Robocopy sync multiple folders – to one location – batch script

From Wikipedia:

Robocopy, or “Robust File Copy“, is a command-line directory and/or file replication command. Robocopy functionally replaces Xcopy, with more options. It has been available as part of the Windows Resource Kit starting with Windows NT 4.0, and was first introduced as a standard feature in Windows Vista and Windows Server 2008.

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.



  1. 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
    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
  2. Save it where you want your backups to be stored (destination). Use whichever name you like. For example robocopy sync unicode folders.bat
  3. 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:
  4. 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

Change process priority for all running instances


The following script sets all processes with a matching filename to different priorities.

Im my case I am using this to change the priority of my Minecraft server between high and belownormal depending on whether I’m just running the server or managing it. I had to set the same CPU priority for all running instances of the same processes quick and easy.


Change blue to the software you are using and red to the priority to wish to use. Paste code into notepad (or a better replacement such as Notepad++) and save as a *.bat file. Add to schedule or as a shortcut.

You can for example replace java.exe to explorer.exe if you wish to prioritize moving/copying files.

Batch Code

set pid=
FOR /F "tokens=2" %%i IN ('tasklist ^| Find /i "java.exe"') DO CALL process -p %%i high
goto :EOF


Craig PeacocksĀ process.exe command-line tool. Download directly or from his site!
(Thank you for the permission to mirror Craig!)
Place this in the same folder as the batch script or in your windows folder for global use.

Tags: Set process priority for multiple processes. Batch windows xp vista 7 change process priority shortcut. Quickly change process priority for all instances of a running process. Set cpu process priority shortcut.