问题
I'm looking for a cross platform file system watcher, similar to the FileSystemWatcher class in .NET. As it's for a daemon/service, I'm not keen on Qt's QFileSystemWatcher. I'd really like to avoid it as I don't want to have a dependency on Qt as my program is going to be a daemon.
I've also seen a proposal for such a class to be included in Boost, but as far as I know such a class has not yet been included.
Is there a cross platform C++ file system watcher?
回答1:
Qt is divided into modules, so using this feature doesn't mean you have to use the GUI library.
QFileSystemWatcher is in QtCore, which has no GUI functionality.
回答2:
I have not used this (I came to this question looking for alternatives), but http://code.google.com/p/simplefilewatcher seems to be a good option. It is not currently maintained, but the relevant APIs are probably fairly stable. I'll try to remember to update this answer if I use this library.
回答3:
As an alternative there is also "Entropia File System Watcher"
https://bitbucket.org/SpartanJ/efsw which is a fork of the simple-file-watcher.
efsw currently supports the following platforms:
Linux via inotify
Windows via I/O Completion Ports
Mac OS X via FSEvents or kqueue
FreeBSD/BSD via kqueue
OS-independent generic watcher (polling the disk for directory snapshots and comparing them periodically)
If any of the backend fails to start by any reason, it will fallback to the OS-independent implementation.
回答4:
For completeness sake, it is also worth mentioning Poco's DirectoryWatcher.
来源:https://stackoverflow.com/questions/10164341/cross-platform-c-filesystem-watcher