C++ 从POCO DirectoryWatcher接收到重复事件
我试图使用POCO文件系统库中的DirectoryWatcher类来监视特定文件夹的更改。代码非常简单,如下所示:C++ 从POCO DirectoryWatcher接收到重复事件,c++,linux,poco-libraries,C++,Linux,Poco Libraries,我试图使用POCO文件系统库中的DirectoryWatcher类来监视特定文件夹的更改。代码非常简单,如下所示: Monitor::Monitor() { pattern = new Glob("/path/to/dir/*.dat", Glob::GLOB_DOT_SPECIAL); watcher = new DirectoryWatcher(std::string("/path/to/dir")); watcher
Monitor::Monitor() {
pattern = new Glob("/path/to/dir/*.dat",
Glob::GLOB_DOT_SPECIAL);
watcher = new DirectoryWatcher(std::string("/path/to/dir"));
watcher->itemAdded += delegate(this, &Monitor::onFileAdded);
watcher->itemModified += delegate(this, &Monitor::onFileChanged);
}
void Monitor::onFileAdded(const DirectoryWatcher::DirectoryEvent& addEvent) {
if (pattern->match(addEvent.item.path())) {
std::cout << "File added: " << addEvent.item.path() << std::endl;
}
}
void Monitor::onFileChanged(const DirectoryWatcher::DirectoryEvent& changeEvent) {
if (pattern->match(changeEvent.item.path())) {
std::cout << "File changed: " << changeEvent.item.path() << std::endl;
}
}
Monitor::Monitor(){
pattern=newglob(“/path/to/dir/*.dat”,
Glob::Glob_DOT_SPECIAL);
watcher=newdirectorywatcher(std::string(“/path/to/dir”);
观察者->项目添加+=委托(此,&监视器::未引导);
观察者->项目修改+=委托(此,&Monitor::onFileChanged);
}
无效监视器::onfiled(const DirectoryWatcher::DirectoryEvent和addEvent){
if(模式->匹配(addEvent.item.path()){
标准::cout