[C++]监控特定文件夹的事件:三种解决方法汇总
<iframe align="center" marginwidth="0" marginheight="0" src="http://www.zealware.com/csdnblog336280.html" frameborder="0" width="336" scrolling="no" height="280"></iframe><div class="postText">监控特定文件夹的事件:三种解决方法汇总<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />LDBIVR程序中要监视特定文件夹的文件落地或者删除事件,本来要用SHELL中的事件通知机制,后来因为要考虑到各种意外事件,如服务意外退出、服务器崩溃等,遂作罢。
对于目录事件异步通知,大致有三个方法:
调用Windows的api函数ReadDirectoryChanges监视指定目录中文件(推荐使用),这个使用异步IO:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/readdirectorychangesw.asp
The ReadDirectoryChangesW function retrieves information that describes the changes within a directory.
To track changes on a volume, see change journals.
BOOL ReadDirectoryChangesW(
HANDLE hDirectory,
LPVOID lpBuffer,
DWORD nBufferLength,
BOOL bWatchSubtree,
DWORD dwNotifyFilter,
LPDWORD lpBytesReturned,
LPOVERLAPPED lpOverlapped,
LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
);
或者用SHChangeNotifyRegister和SHChangeNotifyDeregister来注册事件SHChangeNotify:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/functions/shchangenotify.asp
SHChangeNotify Function
<div style="margin: 0cm 0cm 0pt; text-align: center;" class="MsoNormal">
页:
[1]