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

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.

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.


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.