How can I monitor a Windows directory for changes?

后端 未结 7 1955
感情败类
感情败类 2020-11-29 22:32

When a change is made within a directory on a Windows system, I need a program to be notified immediately of the change.

Is there some way of executing a program whe

相关标签:
7条回答
  • 2020-11-29 23:09

    FileSystemWatcher is the right answer except that it used to be that FileSystemWatcher only worked for a 'few' changes at a time. That was because of an operating system buffer. In practice whenever many small files are copied, the buffer that holds the filenames of the files changed is overrun. This buffer is not really the right way to keep track of recent changes, since the OS would have to stop writing when the buffer is full to prevent overruns.

    Microsoft instead provides other facilities (EDIT: like change journals) to truly capture all changes. Which essentially are the facilities that backup systems use, and are complex on the events that are recorded. And are also poorly documented.

    A simple test is to generate a big number of small files and see if they are all reported on by the FileSystemWatcher. If you have a problem, I suggest to sidestep the whole issue and scan the file system for changes at a timed interval.

    0 讨论(0)
提交回复
热议问题