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

9

5

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?

nhinkle

Posted 2012-10-31T19:54:48.193

Reputation: 35 057

@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 – 2014-10-03T09:03:19.173

Testing Freefilesync now.. it seems to be the tool I needed. – Durden81 – 2014-10-03T10:45:41.273

Does HAVE to be Robocopy? – Ƭᴇcʜιᴇ007 – 2012-10-31T20:05:55.287

@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 – 2012-10-31T20:46:16.613

Answers

7

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.

Anirudh Ramanathan

Posted 2012-10-31T19:54:48.193

Reputation: 704

1yeah, 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 – 2015-01-16T08:58:53.077

12

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.


Joseph

Posted 2012-10-31T19:54:48.193

Reputation: 346

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. – CoolHandLouis – 2017-02-05T08:03:23.503

5

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.

Ashley Wilson

Posted 2012-10-31T19:54:48.193

Reputation: 91

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 – 2015-03-20T05:52:40.280

@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.. – Ashley Wilson – 2015-03-20T10:46:05.543

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. – Ashley Wilson – 2015-03-20T10:49:39.683

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 – 2015-03-20T17:27:26.120

This is the screenshot: http://i.imgur.com/F7heg9A.png

– Ashley Wilson – 2015-03-23T03:31:28.117

It isn't obvious from the image how to accomplish what the question asks. I didn't see a place to specify a time interval (or are you suggesting real time synch?). – fixer1234 – 2015-03-23T03:40:04.630

The question is for (near) continuous sync, which is what the app I suggested does. I've been using it for a week now. – Ashley Wilson – 2015-03-23T10:04:54.940

The question is how do you accomplish that, not name a tool that can do it. My point was that it isn't clear from the image what settings you would use, which raises the question of whether it even does what is asked. Can you specify what to select in the image to achieve either a particular interval less than a minute, or continuous synching? – fixer1234 – 2015-03-23T15:18:55.783

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. – Ashley Wilson – 2015-03-24T06:05:59.110

Software recommendations are a special animal on SU because the site tries to discourage lists of software titles as answers, and spam is a problem. Software recommendations should explain how to solve the problem, include relevant information about the product, and information on your experience with it. If you have a connection with the product, that needs to be disclosed. I've moved all of that from your comments into the answer, which now has everything it needs to be a good answer. I upvoted it. – fixer1234 – 2015-03-24T06:30:30.763

Thank you for adding the screenshot, and also for the upvote. I have added step-by-step instructions to activate realtime sync, and some additional detail. For the record, I have no affiliation with the software; just found a link to this (old) software in a forum. Googling the name of the software will find many references and recommendations. I have also found a YouTube videos which show the software in action, although it shows an older version and the options are not in the same place: YouTube Link

– Ashley Wilson – 2015-03-24T06:47:01.533

The program monitors all the changes in the status of Origin and, every 10 seconds, reflects the same changes in the Destination. It then waits some 10 seconds which has the purpose of avoiding an useless consumption of processor, in fact, if a file is modified twice in 10 seconds, It will only be copied once, which reduces two fold the consumption of processor. – Luke Yan – 2016-03-08T23:46:39.803