gpt4 book ai didi

c++ - 使用 Poco 的多深度目录观察器

转载 作者:太空宇宙 更新时间:2023-11-04 13:02:50 33 4
gpt4 key购买 nike

如何使用 POCO 创建多深度目录观察器?

如果它主要在D:\ddd,我们甚至去到D:\ddd\d1\d2\d3\NewTextDoc.txt,那么它也是应该通知我。我只能对初始目录执行此操作。我使用了事件监听器,如果初始目录中发生任何事情,它们会通知我。

这是我的有效代码:

try
{
AutoPtr<PropertyFileConfiguration> pConf = new
PropertyFileConfiguration("EventListener.properties");
Poco::DirectoryWatcher dirWatcher(pConf->getString("path"),
Poco::DirectoryWatcher::DW_FILTER_ENABLE_ALL,
Poco::DirectoryWatcher::DW_DEFAULT_SCAN_INTERVAL);

dirWatcher.itemModified += Poco::delegate(this, &ClsDirWatcher::onFileModified); //good
dirWatcher.itemMovedFrom += Poco::delegate(this, &ClsDirWatcher::onFileMovedFrom); //no way, seems only linux
dirWatcher.itemMovedTo += Poco::delegate(this, &ClsDirWatcher::onFileMovedTo); //no way, seems only linux
dirWatcher.itemAdded += Poco::delegate(this, &ClsDirWatcher::onFileAdded); //working fine
dirWatcher.itemRemoved += Poco::delegate(this, &ClsDirWatcher::onFileRemoved); //lol!!!

waitForTerminationRequest();
}
catch (Poco::Exception& exc)
{
logger().log(exc);
}

最佳答案

我遇到了同样的问题。根据Poco documentation :

Note that changes to files in subdirectories of the watched directory are not reported. Separate DirectoryWatcher objects must be created for these directories if they should be watched.

所以您需要做的是为每个您想要监视的现有子目录生成一个新的目录监视程序。您还需要在 itemAdded 委托(delegate)中放置一些逻辑,以便在您正在监视的目录中创建新目录时生成新的监视器。

关于c++ - 使用 Poco 的多深度目录观察器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43497652/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com