Watching multiple directories with ReadDirectoryChangesW

  c++, winapi, windows

I need to watch multiple directories for chile changes (mainly new files).
I found a good article here.
The code works well does exactly what I want.
But only for a single directory.

I tried different things, like creating two handles and call ReadDirectoryChangesW two times.
But nothing worked so far.
I think creating a second CFileWatcher object would solve my problem but if I need, for example, to monitor 10 directories I would have 10 threads running and I think this is not a good solution.

I also found this post.
But my directories contain lot of data (each directory at least > 10.000) files and a new file is added every 15seconds. So I would prefer a solution where I only watch specific directories.

Would be very happy about every idea or advice.

Source: Windows Questions

One Reply to “Watching multiple directories with ReadDirectoryChangesW”

  • It is easy;You can create multiple CFileSystemWatcher pointing to different directory and add corresponding listeners.

    Regards,
    Sadique

LEAVE A COMMENT