Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
    
Does HAVE to be Robocopy? –  Ƭᴇcʜιᴇ007 Oct 31 '12 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 '12 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 '14 at 9:03
    
Testing Freefilesync now.. it seems to be the tool I needed. –  Durden81 Oct 3 '14 at 10:45

3 Answers 3

up vote 3 down vote accepted

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.

share|improve this answer
    
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 at 8:58

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.


share|improve this answer

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.

share|improve this answer
    
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 at 5:52
    
@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 Mar 20 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. –  Ashley Mar 20 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 at 17:27
    
This is the screenshot: i.imgur.com/F7heg9A.png –  Ashley Mar 23 at 3:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.