Can Robocopy monitor files on a time increment of less than one minute?

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?


Solution 1:

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.

Solution 2:

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.


  • For more info on System.IO.FileSystemWatcher please visit its MSDN page.
  • For some more examples of events in PowerShell visit this blog I found useful.
  • For a primer on Windows PowerShell I've found this site to be useful (I like their tips of the day).
  • If you're using an older version of windows or for some reason you don't have PowerShell installed you can download the Windows Management Framework 4.0.