I would like to do the following in a Windows environment:

monitor a folder for the appearance of new file(s), when such files appear, move them into a different folder. Does not necessarily need to occur in real-time, but would like to keep it to within, say, 15 minutes of the appearance of the file.

In Linux, there is a kernel hook to monitor in realtime the appearance of new files in a directory, I don't know if something similar exists in Windows, or if that would even be a desirable solution. I'd like some suggestions on how to achieve this. I use rsync regularly in Linux; is it as reliable under Windows? More importantly, is rsync capable of handling a situation where a file has appeared but has not yet been completely written to - in this case can rsync (or other tool) wait until the file has been completely written before trying to move it?

I'm sure other sysadmins have had to deal with this type of issue, so rather than reinventing the wheel myself, I'd like to hear what others have done.


You could probably do that with something like this batch file:


move "f:\path\*.ext" "g:\path\"

GOTO loop

It's not smart or pretty, but I do use it myself on occasion.

| improve this answer | |

Robocopy is supposed to do this, but disclaimer: I've never tried it myself.

Here's a link to a previous question that should have some good ansers for you. That way, you can use a tool built into Windows, and not have to mess around with batch scripts and the like.

If this ends up working for you, definitely come back and post! I'm very interested in seeing how the implementation works out.

| improve this answer | |

You can mitigate the issue about file completion by sending a second, even empty file after your actual file has completed. The file watcher should check for this trigger file, while your script then handles your data file.

| improve this answer | |
  • Good suggestion, although I don't think it's necessary because what I've read is that under Windows rsync will skip files which are write-in-process. – Michael Martinez Aug 12 '14 at 22:06
  • Getting more off topic here, but a trigger file also will prevent processing a failed file transfer. But requirements may vary. – sastorsl Aug 13 '14 at 17:36

If I run across problems like this and I don't find a suitable easy and understandable solution online I use my (limited) programming skills to find a solution.

In this case you're lucky that there is a .Net-Class provided by Microsoft, called "FileSystemWatcher" but sadly it doesn't check for copy completion (just create, change and delete-events).

However I found this: http://www.dotnetfunda.com/articles/show/1312/detect-file-copy-completion-in-filesystemwatcher

This guy wrote a fiddle that checks the folder you specify for new file creations and continues to process whatever you want when the file is complete (by trying to open it in a certain interval which will not work if the file is still being written).

In the given code you can insert your move-files-command after "//Start processing..".

I know this is not the easiest solution but it works as you intended and I didn't find a tool that will do this for you and given the fact that this is pretty easy to program as you mostly just have to copy&paste you are safer as you would be if you would take any random program from the internet.

| improve this answer | |

System Center Orchestrator works great for this. Here is Microsofts Documentation on this. http://technet.microsoft.com/en-us/library/hh440534.aspx

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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