13

Robocopy has the option to monitor the source directory, and copy over any files that have changes. You can specify how many changes in the directory must occur before copying (/mon n where n is the number of changes) and how long to wait before rescanning (/mot t where t is the time to wait in minutes).

I'd like to monitor a folder nearly continuously, since there's only 1 file I'm scanning for, and I want changes to be basically instant. I can't seem to make robocopy monitor for a timespan less than one minute though. I've tried /mot 0.5 and it fails. I also tried /mot 0 and robocopy just exits after scanning once, without monitoring continuously.

How can I make robocopy scan a folder near-continuously, with time increments of less than 1 minute? Alternatively, is there any other command line tool that can constantly monitor a file source and copy changes in real time?

5
  • Does HAVE to be Robocopy? Oct 31, 2012 at 20:05
  • @techie007 if there's something else that achieves the same requirements, that would be fine, although I'd like to avoid third-party tools if possible. But if there's a perfect solution that's third-party then I'm willing to consider it.
    – nhinkle
    Oct 31, 2012 at 20:46
  • @techie007 - I have the same exact problem as nhinkle, and I am using Robocopy in the same exact way. If you do know of an alternative solution that works well on Windows I am open to it. Please share it with us
    – Durden81
    Oct 3, 2014 at 9:03
  • Testing Freefilesync now.. it seems to be the tool I needed.
    – Durden81
    Oct 3, 2014 at 10:45
  • It appears you can just run a scheduled task (in fractions of a second or create a loop that just keeps the same pseudo "service" running) and Robocopy instantly continues from where it left off. But I am using the /MT:16 (threads) flag, which likely helps.
    – jacktrader
    Dec 25, 2022 at 0:42

4 Answers 4

8

Robocopy

/mot:<M>
Monitors source, and runs again in M minutes if changes are detected.

As it accepts only minutes as argument, I guess you can't force it to run more often. You could however, run it using a batch file and let the timing & looping occur in the batch-file or in scheduled tasks rather than within robocopy.

1
  • 1
    yeah, I use "ping -n 1 -w 500 1.2.3.4>NUL" to sleep half a second, then loop it with a :LABEL and a GOTO statement (in cmd)
    – Stig Eide
    Jan 16, 2015 at 8:58
20

Your tags state you are using Windows 8. This is good, since you have the great tool that is PowerShell, and a handy little cmdlet named Register-ObjectEvent.

Create a text file, change the extension to .ps1, paste the script below into the file. Change the $watchedFolder variable to the folder you want to watch. Change the Do-Something function to include your robocopy command or whatever. Run the script, as long as the script is running that function will run (nearly instantly!) whenever a file or folder is changed in the watched folder.

You could have this script run at windows startup and it would be running in the background at all times without using a timer.

$block = {    
    function Do-Something
    {
        param ($message, $event)
        # function to call when event is raised
        # do a robocopy or whatever

        Start-Process cmd.exe "/C echo $("{0} {1}" -f $event.SourceEventArgs.FullPath, $message)&pause"
    }

    $watchedFolder = "C:\Users\Admin-PC\Desktop"
    $watcher = New-Object System.IO.FileSystemWatcher
    $watcher.Path = $watchedFolder

    Register-ObjectEvent -InputObject $watcher -EventName Created -SourceIdentifier File.Created -Action { Do-Something "Created" $event }
    Register-ObjectEvent -InputObject $watcher -EventName Deleted -SourceIdentifier File.Deleted -Action { Do-Something "Deleted" $event }
    Register-ObjectEvent -InputObject $watcher -EventName Changed -SourceIdentifier File.Changed -Action { Do-Something "Changed" $event }
    Register-ObjectEvent -InputObject $watcher -EventName Renamed -SourceIdentifier File.Renamed -Action { Do-Something "Renamed" $event }
}

$encodedBlock = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($block))

Start-Process PowerShell.exe -verb Runas -argumentlist '-WindowStyle Hidden', '-NoExit', '-EncodedCommand', $encodedBlock

See It In Action


  1. Run the saved script.
    Run the saved script.

  2. You will see a console window flash, after they close the only indication it's running will be a couple new processes.
    enter image description here

  3. Do some stuff on your desktop to test.
    enter image description here

  4. End the created PowerShell process when you no longer want it to run.

Some Background Info - In case you are unfamiliar with the tools used in this answer.


1
  • 2
    This is the best answer. This solution is event-driven, which means it never uses cpu until a change occurs, and then the program runs immediately in response. Also, excellent write-up. Feb 5, 2017 at 8:03
6

DSynchronize is a stand-alone utility that let you periodically synchronize two or more folders on Hard Disk, Floppy Disk, LAN, USB Key, CD-DVD (with packet writing software) and FTP server. It's not exactly what the question is about, but the nearest thing I could find.

I, too was looking for a solution to the 1-minute minimum time in Robocopy and found this two-year old question. I ended up having this software suggested to me, and that's what I'm using. For the record, I have no affiliation with the software.

Pros:

  • Has real-time sync.
  • Can add multiple folder pairs, and choose which pairs are active at a given time using checkboxes next to them.
  • No installer, standalone program.
  • You can exclude or include files through patterns or by modified time by clicking the 'filter' button.
  • (others; see screenshot below. The checkboxes and buttons have additional help tooltips.)

Cons:

  • Is a GUI utility, no command-line switches available
  • Folder pairs all share the same settings

screenshot

The realtime sync option is marked in the screenshot under the section 'Special Options'. This would be what the question seems to describe as the goal. If it is not checked and you don't have a timer set, then you can to click the 'Synchronize' button to start a one-time sync.

How to sync two folders:

  • Select a source folder which you want to monitor by using the browse dialogue in the top-left corner.
  • Select a destination folder where you want to copy the changes to in the top-right corner.
  • (Optional) If you manually typed-in the folder path instead of using the browse dialogue, click the 'TEST' button between the two boxes at the top to see if those folders actually exist. You will also want to check the 'Create folder if not exists' in most cases to make sure new folders are copied across, as it's unchecked by default and so the program only copies files by default.
  • Tick the 'Realtime sync' checkbox. The syncing is now active, and all changes from the left side folder will be copied across to the right side folder.

I also found this YouTube video, which shows the software in action. It shows an older version and the options are not in the same place, but it provides a feel for how the software works.

12
  • 1
    The question asks how to make something happen (in Robocopy). It's fine to suggest an alternate solution, explaining how to accomplish the same result using another tool. However, this doesn't explain how to actually solve the problem.
    – fixer1234
    Mar 20, 2015 at 5:52
  • 1
    @fixer1234 I was originally just planning to comment on the question, but apparently my account is too new to do that (I can comment on my own answer, apparently). I too was looking for a solution to the 1-minute minimum time in robocopy and found this two-year old question. I ended up having the above software suggested to me, and that's what I'm using. Thought others in the same situation would find it useful, that is all. For a seemingly simple task (folder syncing), it's amazing how much you have to search to find a solution.. Mar 20, 2015 at 10:46
  • As for clarity of my answer - I wish I could attach the screenshot (again, account is too new to allow that) which would've made it much more clearer - it is a one-screen GUI and all options are clearly visible and simple to understand. Mar 20, 2015 at 10:49
  • If you use any file sharing service, just add a link to your image and someone will embed it for you. If you don't regularly use one, there are lots of free ones (like imgur.com).
    – fixer1234
    Mar 20, 2015 at 17:27
  • 1
    The checkbox 'Realtime sync' is highlighted in the image, and is front-and-center in the UI. I don't see how anyone could miss that... If someone can look at the answer by Joseph and is expected to understand that, then surely, they can see a checkbox which says 'Realtime sync' and understand that it does... realtime sync?! All I got from a forum somewhere was a link to that page and nothing else and it was quite straight-forward to me how to use it. I will spell it out in the answer then, hopefully that will satisfy you. Mar 24, 2015 at 6:05
-1

use the /MON 1 switch, every time the file is changed robocopy will sync

3
  • 3
    Perhaps explaining how /mon differs from the accepted answer of /mot would make this a better and more helpful answer. Feb 24, 2021 at 4:34
  • even using only /mon:1 it will wait for 1 minute, using /mon:1 with /mot:0 will still wait for 1 minute.
    – Arsenal
    Nov 16, 2021 at 11:23
  • I think it got downvoted because 1) it's not what the OP asked, 2) doesn't answer the question, and 3) is actually wrong. The correct Syntax is /MON:1, but if /MOT is not specified, the default is 1 minute regardless. So as far as I can tell, it can't use fractions and there is no other option. It's all you get.
    – jacktrader
    Dec 25, 2022 at 0:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .