- 浏览: 4178597 次
最新评论
[C++]监控特定文件夹的事件:三种解决方法汇总
监控特定文件夹的事件:三种解决方法汇总<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
LDBIVR程序中要监视特定文件夹的文件落地或者删除事件,本来要用SHELL中的事件通知机制,后来因为要考虑到各种意外事件,如服务意外退出、服务器崩溃等,遂作罢。
对于目录事件异步通知,大致有三个方法:
调用Windows的api函数ReadDirectoryChanges监视指定目录中文件(推荐使用),这个使用异步IO:
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:
SHChangeNotify Function |
Notifies the system of an event that an application has performed. An application should use this function if it performs an action that may affect the Shell.
Syntax
voidSHChangeNotify(
LONGwEventId,
UINTuFlags,
LPCVOIDdwItem1,
LPCVOIDdwItem2
);
这个SHELL事件,有人这么介绍(http://qk.5nx.com/article_view.asp?id=11)。
或者调用API函数-FindFirstChangeNotification 、FindCloseChangeNotification、FindNextChangeNotification 和WaitForSingleObject :
The FindFirstChangeNotification function creates a change notification handle and sets up initial change notification filter conditions. A wait on a notification handle succeeds when a change matching the filter conditions occurs in the specified directory or subtree. However, the function does not indicate the change that satisfied the wait condition.
To retrieve information about the specific change as part of the notification, use the ReadDirectoryChangesW function.
HANDLE FindFirstChangeNotification(
LPCTSTR lpPathName,
BOOL bWatchSubtree,
DWORD dwNotifyFilter
);
著名的FileMon工具用的是虚拟驱动。
相关资源:
1:《监视程序的编制》;
2:《Win32中的目录监控》;
3:《change journals》;
4:《CDirectoryChangeWatcher - ReadDirectoryChangesW all wrapped up》;
5:《监测目录活动》;
6:《请问如何监视系统对文件的访问?》。
Disclaimers:
Programmer’s Blog List: |
<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><stroke joinstyle="miter"></stroke><formulas><f eqn="if lineDrawn pixelLineWidth 0"></f><f eqn="sum @0 1 0"></f><f eqn="sum 0 0 @1"></f><f eqn="prod @2 1 2"></f><f eqn="prod @3 21600 pixelWidth"></f><f eqn="prod @3 21600 pixelHeight"></f><f eqn="sum @0 0 1"></f><f eqn="prod @6 1 2"></f><f eqn="prod @7 21600 pixelWidth"></f><f eqn="sum @8 21600 0"></f><f eqn="prod @7 21600 pixelHeight"></f><f eqn="sum @10 21600 0"></f></formulas><path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"></path><lock v:ext="edit" aspectratio="t"></lock></shapetype><shape id="_x0000_i1025" style="WIDTH: 0.75pt; HEIGHT: 0.75pt" alt="" type="#_x0000_t75"></shape> |
本文档仅供参考。本文档所包含的信息代表了在发布之日,zhengyun_ustc对所讨论问题的当前看法,zhengyun_ustc不保证所给信息在发布之日以后的准确性。
用户应清楚本文档的准确性及其使用可能带来的全部风险。可以复制和传播本文档,但须遵守以下条款:
- 复制时不得修改原文,复制内容须包含所有页 ;
- 所有副本均须含有 zhengyun_ustc的版权声明以及所提供的其它声明 ;
- 不得以赢利为目的对本文档进行传播 。
监控特定文件夹的事件:三种解决方法汇总<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
LDBIVR程序中要监视特定文件夹的文件落地或者删除事件,本来要用SHELL中的事件通知机制,后来因为要考虑到各种意外事件,如服务意外退出、服务器崩溃等,遂作罢。
对于目录事件异步通知,大致有三个方法:
调用Windows的api函数ReadDirectoryChanges监视指定目录中文件(推荐使用),这个使用异步IO:
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:
SHChangeNotify Function |
Notifies the system of an event that an application has performed. An application should use this function if it performs an action that may affect the Shell.
Syntax
voidSHChangeNotify(
LONGwEventId,
UINTuFlags,
LPCVOIDdwItem1,
LPCVOIDdwItem2
);
这个SHELL事件,有人这么介绍(http://qk.5nx.com/article_view.asp?id=11)。
或者调用API函数-FindFirstChangeNotification 、FindCloseChangeNotification、FindNextChangeNotification 和WaitForSingleObject :
The FindFirstChangeNotification function creates a change notification handle and sets up initial change notification filter conditions. A wait on a notification handle succeeds when a change matching the filter conditions occurs in the specified directory or subtree. However, the function does not indicate the change that satisfied the wait condition.
To retrieve information about the specific change as part of the notification, use the ReadDirectoryChangesW function.
HANDLE FindFirstChangeNotification(
LPCTSTR lpPathName,
BOOL bWatchSubtree,
DWORD dwNotifyFilter
);
著名的FileMon工具用的是虚拟驱动。
相关资源:
1:《监视程序的编制》;
2:《Win32中的目录监控》;
3:《change journals》;
4:《CDirectoryChangeWatcher - ReadDirectoryChangesW all wrapped up》;
5:《监测目录活动》;
6:《请问如何监视系统对文件的访问?》。
Disclaimers:
Programmer’s Blog List: |
<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><stroke joinstyle="miter"></stroke><formulas><f eqn="if lineDrawn pixelLineWidth 0"></f><f eqn="sum @0 1 0"></f><f eqn="sum 0 0 @1"></f><f eqn="prod @2 1 2"></f><f eqn="prod @3 21600 pixelWidth"></f><f eqn="prod @3 21600 pixelHeight"></f><f eqn="sum @0 0 1"></f><f eqn="prod @6 1 2"></f><f eqn="prod @7 21600 pixelWidth"></f><f eqn="sum @8 21600 0"></f><f eqn="prod @7 21600 pixelHeight"></f><f eqn="sum @10 21600 0"></f></formulas><path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"></path><lock v:ext="edit" aspectratio="t"></lock></shapetype><shape id="_x0000_i1025" style="WIDTH: 0.75pt; HEIGHT: 0.75pt" alt="" type="#_x0000_t75"></shape> |
本文档仅供参考。本文档所包含的信息代表了在发布之日,zhengyun_ustc对所讨论问题的当前看法,zhengyun_ustc不保证所给信息在发布之日以后的准确性。
用户应清楚本文档的准确性及其使用可能带来的全部风险。可以复制和传播本文档,但须遵守以下条款:
- 复制时不得修改原文,复制内容须包含所有页 ;
- 所有副本均须含有 zhengyun_ustc的版权声明以及所提供的其它声明 ;
- 不得以赢利为目的对本文档进行传播 。
监控特定文件夹的事件:三种解决方法汇总<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
LDBIVR程序中要监视特定文件夹的文件落地或者删除事件,本来要用SHELL中的事件通知机制,后来因为要考虑到各种意外事件,如服务意外退出、服务器崩溃等,遂作罢。
对于目录事件异步通知,大致有三个方法:
调用Windows的api函数ReadDirectoryChanges监视指定目录中文件(推荐使用),这个使用异步IO:
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:
SHChangeNotify Function |
Notifies the system of an event that an application has performed. An application should use this function if it performs an action that may affect the Shell.
Syntax
voidSHChangeNotify(
LONGwEventId,
UINTuFlags,
LPCVOIDdwItem1,
LPCVOIDdwItem2
);
这个SHELL事件,有人这么介绍(http://qk.5nx.com/article_view.asp?id=11)。
或者调用API函数-FindFirstChangeNotification 、FindCloseChangeNotification、FindNextChangeNotification 和WaitForSingleObject :
The FindFirstChangeNotification function creates a change notification handle and sets up initial change notification filter conditions. A wait on a notification handle succeeds when a change matching the filter conditions occurs in the specified directory or subtree. However, the function does not indicate the change that satisfied the wait condition.
To retrieve information about the specific change as part of the notification, use the ReadDirectoryChangesW function.
HANDLE FindFirstChangeNotification(
LPCTSTR lpPathName,
BOOL bWatchSubtree,
DWORD dwNotifyFilter
);
著名的FileMon工具用的是虚拟驱动。
相关资源:
1:《监视程序的编制》;
2:《Win32中的目录监控》;
3:《change journals》;
4:《CDirectoryChangeWatcher - ReadDirectoryChangesW all wrapped up》;
5:《监测目录活动》;
6:《请问如何监视系统对文件的访问?》。
Disclaimers:
Programmer’s Blog List: |
<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><stroke joinstyle="miter"></stroke><formulas><f eqn="if lineDrawn pixelLineWidth 0"></f><f eqn="sum @0 1 0"></f><f eqn="sum 0 0 @1"></f><f eqn="prod @2 1 2"></f><f eqn="prod @3 21600 pixelWidth"></f><f eqn="prod @3 21600 pixelHeight"></f><f eqn="sum @0 0 1"></f><f eqn="prod @6 1 2"></f><f eqn="prod @7 21600 pixelWidth"></f><f eqn="sum @8 21600 0"></f><f eqn="prod @7 21600 pixelHeight"></f><f eqn="sum @10 21600 0"></f></formulas><path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"></path><lock v:ext="edit" aspectratio="t"></lock></shapetype><shape id="_x0000_i1025" style="WIDTH: 0.75pt; HEIGHT: 0.75pt" alt="" type="#_x0000_t75"></shape> |
本文档仅供参考。本文档所包含的信息代表了在发布之日,zhengyun_ustc对所讨论问题的当前看法,zhengyun_ustc不保证所给信息在发布之日以后的准确性。
用户应清楚本文档的准确性及其使用可能带来的全部风险。可以复制和传播本文档,但须遵守以下条款:
- 复制时不得修改原文,复制内容须包含所有页 ;
- 所有副本均须含有 zhengyun_ustc的版权声明以及所提供的其它声明 ;
- 不得以赢利为目的对本文档进行传播 。
监控特定文件夹的事件:三种解决方法汇总<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
LDBIVR程序中要监视特定文件夹的文件落地或者删除事件,本来要用SHELL中的事件通知机制,后来因为要考虑到各种意外事件,如服务意外退出、服务器崩溃等,遂作罢。
对于目录事件异步通知,大致有三个方法:
调用Windows的api函数ReadDirectoryChanges监视指定目录中文件(推荐使用),这个使用异步IO:
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:
SHChangeNotify Function |
Notifies the system of an event that an application has performed. An application should use this function if it performs an action that may affect the Shell.
Syntax
voidSHChangeNotify(
LONGwEventId,
UINTuFlags,
LPCVOIDdwItem1,
LPCVOIDdwItem2
);
这个SHELL事件,有人这么介绍(http://qk.5nx.com/article_view.asp?id=11)。
或者调用API函数-FindFirstChangeNotification 、FindCloseChangeNotification、FindNextChangeNotification 和WaitForSingleObject :
The FindFirstChangeNotification function creates a change notification handle and sets up initial change notification filter conditions. A wait on a notification handle succeeds when a change matching the filter conditions occurs in the specified directory or subtree. However, the function does not indicate the change that satisfied the wait condition.
To retrieve information about the specific change as part of the notification, use the ReadDirectoryChangesW function.
HANDLE FindFirstChangeNotification(
LPCTSTR lpPathName,
BOOL bWatchSubtree,
DWORD dwNotifyFilter
);
著名的FileMon工具用的是虚拟驱动。
相关资源:
1:《监视程序的编制》;
2:《Win32中的目录监控》;
3:《change journals》;
4:《CDirectoryChangeWatcher - ReadDirectoryChangesW all wrapped up》;
5:《监测目录活动》;
6:《请问如何监视系统对文件的访问?》。
Disclaimers:
Programmer’s Blog List: |
<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><stroke joinstyle="miter"></stroke><formulas><f eqn="if lineDrawn pixelLineWidth 0"></f><f eqn="sum @0 1 0"></f><f eqn="sum 0 0 @1"></f><f eqn="prod @2 1 2"></f><f eqn="prod @3 21600 pixelWidth"></f><f eqn="prod @3 21600 pixelHeight"></f><f eqn="sum @0 0 1"></f><f eqn="prod @6 1 2"></f><f eqn="prod @7 21600 pixelWidth"></f><f eqn="sum @8 21600 0"></f><f eqn="prod @7 21600 pixelHeight"></f><f eqn="sum @10 21600 0"></f></formulas><path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"></path><lock v:ext="edit" aspectratio="t"></lock></shapetype><shape id="_x0000_i1025" style="WIDTH: 0.75pt; HEIGHT: 0.75pt" alt="" type="#_x0000_t75"></shape> |
本文档仅供参考。本文档所包含的信息代表了在发布之日,zhengyun_ustc对所讨论问题的当前看法,zhengyun_ustc不保证所给信息在发布之日以后的准确性。
用户应清楚本文档的准确性及其使用可能带来的全部风险。可以复制和传播本文档,但须遵守以下条款:
- 复制时不得修改原文,复制内容须包含所有页 ;
- 所有副本均须含有 zhengyun_ustc的版权声明以及所提供的其它声明 ;
- 不得以赢利为目的对本文档进行传播 。
监控特定文件夹的事件:三种解决方法汇总<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
LDBIVR程序中要监视特定文件夹的文件落地或者删除事件,本来要用SHELL中的事件通知机制,后来因为要考虑到各种意外事件,如服务意外退出、服务器崩溃等,遂作罢。
对于目录事件异步通知,大致有三个方法:
调用Windows的api函数ReadDirectoryChanges监视指定目录中文件(推荐使用),这个使用异步IO:
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:
SHChangeNotify Function |
Notifies the system of an event that an application has performed. An application should use this function if it performs an action that may affect the Shell.
Syntax
voidSHChangeNotify(
LONGwEventId,
UINTuFlags,
LPCVOIDdwItem1,
LPCVOIDdwItem2
);
这个SHELL事件,有人这么介绍(http://qk.5nx.com/article_view.asp?id=11)。
或者调用API函数-FindFirstChangeNotification 、FindCloseChangeNotification、FindNextChangeNotification 和WaitForSingleObject :
The FindFirstChangeNotification function creates a change notification handle and sets up initial change notification filter conditions. A wait on a notification handle succeeds when a change matching the filter conditions occurs in the specified directory or subtree. However, the function does not indicate the change that satisfied the wait condition.
To retrieve information about the specific change as part of the notification, use the ReadDirectoryChangesW function.
HANDLE FindFirstChangeNotification(
LPCTSTR lpPathName,
BOOL bWatchSubtree,
DWORD dwNotifyFilter
);
著名的FileMon工具用的是虚拟驱动。
相关资源:
1:《监视程序的编制》;
2:《Win32中的目录监控》;
3:《change journals》;
4:《CDirectoryChangeWatcher - ReadDirectoryChangesW all wrapped up》;
5:《监测目录活动》;
6:《请问如何监视系统对文件的访问?》。
Disclaimers:
Programmer’s Blog List: |
<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><stroke joinstyle="miter"></stroke><formulas><f eqn="if lineDrawn pixelLineWidth 0"></f><f eqn="sum @0 1 0"></f><f eqn="sum 0 0 @1"></f><f eqn="prod @2 1 2"></f><f eqn="prod @3 21600 pixelWidth"></f><f eqn="prod @3 21600 pixelHeight"></f><f eqn="sum @0 0 1"></f><f eqn="prod @6 1 2"></f><f eqn="prod @7 21600 pixelWidth"></f><f eqn="sum @8 21600 0"></f><f eqn="prod @7 21600 pixelHeight"></f><f eqn="sum @10 21600 0"></f></formulas><path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"></path><lock v:ext="edit" aspectratio="t"></lock></shapetype><shape id="_x0000_i1025" style="WIDTH: 0.75pt; HEIGHT: 0.75pt" alt="" type="#_x0000_t75"></shape> |
本文档仅供参考。本文档所包含的信息代表了在发布之日,zhengyun_ustc对所讨论问题的当前看法,zhengyun_ustc不保证所给信息在发布之日以后的准确性。
用户应清楚本文档的准确性及其使用可能带来的全部风险。可以复制和传播本文档,但须遵守以下条款:
- 复制时不得修改原文,复制内容须包含所有页 ;
- 所有副本均须含有 zhengyun_ustc的版权声明以及所提供的其它声明 ;
- 不得以赢利为目的对本文档进行传播 。
监控特定文件夹的事件:三种解决方法汇总<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
LDBIVR程序中要监视特定文件夹的文件落地或者删除事件,本来要用SHELL中的事件通知机制,后来因为要考虑到各种意外事件,如服务意外退出、服务器崩溃等,遂作罢。
对于目录事件异步通知,大致有三个方法:
调用Windows的api函数ReadDirectoryChanges监视指定目录中文件(推荐使用),这个使用异步IO:
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:
SHChangeNotify Function |
Notifies the system of an event that an application has performed. An application should use this function if it performs an action that may affect the Shell.
Syntax
voidSHChangeNotify(
LONGwEventId,
UINTuFlags,
LPCVOIDdwItem1,
LPCVOIDdwItem2
);
这个SHELL事件,有人这么介绍(http://qk.5nx.com/article_view.asp?id=11)。
或者调用API函数-FindFirstChangeNotification 、FindCloseChangeNotification、FindNextChangeNotification 和WaitForSingleObject :
The FindFirstChangeNotification function creates a change notification handle and sets up initial change notification filter conditions. A wait on a notification handle succeeds when a change matching the filter conditions occurs in the specified directory or subtree. However, the function does not indicate the change that satisfied the wait condition.
To retrieve information about the specific change as part of the notification, use the ReadDirectoryChangesW function.
HANDLE FindFirstChangeNotification(
LPCTSTR lpPathName,
BOOL bWatchSubtree,
DWORD dwNotifyFilter
);
著名的FileMon工具用的是虚拟驱动。
相关资源:
1:《监视程序的编制》;
2:《Win32中的目录监控》;
3:《change journals》;
4:《CDirectoryChangeWatcher - ReadDirectoryChangesW all wrapped up》;
5:《监测目录活动》;
6:《请问如何监视系统对文件的访问?》。
Disclaimers:
Programmer’s Blog List: |
<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><stroke joinstyle="miter"></stroke><formulas><f eqn="if lineDrawn pixelLineWidth 0"></f><f eqn="sum @0 1 0"></f><f eqn="sum 0 0 @1"></f><f eqn="prod @2 1 2"></f><f eqn="prod @3 21600 pixelWidth"></f><f eqn="prod @3 21600 pixelHeight"></f><f eqn="sum @0 0 1"></f><f eqn="prod @6 1 2"></f><f eqn="prod @7 21600 pixelWidth"></f><f eqn="sum @8 21600 0"></f><f eqn="prod @7 21600 pixelHeight"></f><f eqn="sum @10 21600 0"></f></formulas><path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"></path><lock v:ext="edit" aspectratio="t"></lock></shapetype><shape id="_x0000_i1025" style="WIDTH: 0.75pt; HEIGHT: 0.75pt" alt="" type="#_x0000_t75"></shape> |
本文档仅供参考。本文档所包含的信息代表了在发布之日,zhengyun_ustc对所讨论问题的当前看法,zhengyun_ustc不保证所给信息在发布之日以后的准确性。
用户应清楚本文档的准确性及其使用可能带来的全部风险。可以复制和传播本文档,但须遵守以下条款:
- 复制时不得修改原文,复制内容须包含所有页 ;
- 所有副本均须含有 zhengyun_ustc的版权声明以及所提供的其它声明 ;
- 不得以赢利为目的对本文档进行传播 。
监控特定文件夹的事件:三种解决方法汇总<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
LDBIVR程序中要监视特定文件夹的文件落地或者删除事件,本来要用SHELL中的事件通知机制,后来因为要考虑到各种意外事件,如服务意外退出、服务器崩溃等,遂作罢。
对于目录事件异步通知,大致有三个方法:
调用Windows的api函数ReadDirectoryChanges监视指定目录中文件(推荐使用),这个使用异步IO:
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:
SHChangeNotify Function |
Notifies the system of an event that an application has performed. An application should use this function if it performs an action that may affect the Shell.
Syntax
voidSHChangeNotify(
LONGwEventId,
UINTuFlags,
LPCVOIDdwItem1,
LPCVOIDdwItem2
);
这个SHELL事件,有人这么介绍(http://qk.5nx.com/article_view.asp?id=11)。
或者调用API函数-FindFirstChangeNotification 、FindCloseChangeNotification、FindNextChangeNotification 和WaitForSingleObject :
The FindFirstChangeNotification function creates a change notification handle and sets up initial change notification filter conditions. A wait on a notification handle succeeds when a change matching the filter conditions occurs in the specified directory or subtree. However, the function does not indicate the change that satisfied the wait condition.
To retrieve information about the specific change as part of the notification, use the ReadDirectoryChangesW function.
HANDLE FindFirstChangeNotification(
LPCTSTR lpPathName,
BOOL bWatchSubtree,
DWORD dwNotifyFilter
);
著名的FileMon工具用的是虚拟驱动。
相关资源:
1:《监视程序的编制》;
2:《Win32中的目录监控》;
3:《change journals》;
4:《CDirectoryChangeWatcher - ReadDirectoryChangesW all wrapped up》;
5:《监测目录活动》;
6:《请问如何监视系统对文件的访问?》。
Disclaimers:
Programmer’s Blog List: |
<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><stroke joinstyle="miter"></stroke><formulas><f eqn="if lineDrawn pixelLineWidth 0"></f><f eqn="sum @0 1 0"></f><f eqn="sum 0 0 @1"></f><f eqn="prod @2 1 2"></f><f eqn="prod @3 21600 pixelWidth"></f><f eqn="prod @3 21600 pixelHeight"></f><f eqn="sum @0 0 1"></f><f eqn="prod @6 1 2"></f><f eqn="prod @7 21600 pixelWidth"></f><f eqn="sum @8 21600 0"></f><f eqn="prod @7 21600 pixelHeight"></f><f eqn="sum @10 21600 0"></f></formulas><path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"></path><lock v:ext="edit" aspectratio="t"></lock></shapetype><shape id="_x0000_i1025" style="WIDTH: 0.75pt; HEIGHT: 0.75pt" alt="" type="#_x0000_t75"></shape> |
本文档仅供参考。本文档所包含的信息代表了在发布之日,zhengyun_ustc对所讨论问题的当前看法,zhengyun_ustc不保证所给信息在发布之日以后的准确性。
用户应清楚本文档的准确性及其使用可能带来的全部风险。可以复制和传播本文档,但须遵守以下条款:
- 复制时不得修改原文,复制内容须包含所有页 ;
- 所有副本均须含有 zhengyun_ustc的版权声明以及所提供的其它声明 ;
- 不得以赢利为目的对本文档进行传播 。
相关推荐
封装好的自动创建多层文件夹函数: // 如此调用,则会在C:\123目录下创建名为111的文件夹,111文件夹下又自动创建222,依次类推 CreateMultilFolder("C:\123", "111/222/333")
C++创建自定义名称的文件夹 C++创建自定义名称的文件夹 C++创建自定义名称的文件夹 C++创建自定义名称的文件夹 C++创建自定义名称的文件夹 C++创建自定义名称的文件夹 C++创建自定义名称的文件夹 C++创建自定义名称...
C++遍历指定文件夹中的所有文件 遍历方法
在window下,使用c++遍历文件夹及其子文件夹所有文件 并输出文件路径和文件内容。网上的资源大多都只是遍历文件夹,但是我需要打印出文件内容,所以自己弄了两天,这就是我的成果(*^__^*) ……
毕设项目:基于C++、QT的网络视频监控系统 毕设项目:基于C++、QT的网络视频监控系统 毕设项目:基于C++、QT的网络视频监控系统 毕设项目:基于C++、QT的网络视频监控系统 毕设项目:基于C++、QT的网络视频监控系统 ...
vs2017 下 windows C/C++ 删除文件夹以及文件夹里的所有文件,遍历嵌套删除文件及文件夹
C++访问判断文件夹是否存在并访问文件夹以及文件, C++访问判断文件夹是否存在并访问文件夹以及文件
Visual C++ 文件与文件夹属性操作 源代码
用轮询线程对指定文件夹下的文件进行监控!
Visual C++文件与文件夹系统操作 源代码
前段时间做项目需要读取一个文件夹里面所有的txt文件,查询资料后得到以下实现方法: 首先了解一下这个结构体 struct _finddata_t { unsigned attrib; time_t time_create; time_t time_access; time_t time_...
C++中探出打开文件夹对话框并获取文件夹路径,在对选择文件的程序中特别常用
C++遍历指定文件夹下的所有文
c++文件,文件夹操作简单包装类,在vs2005下测试通过
VC++移动/剪切非空文件夹
C++ 获取文件夹下的所有文件名 C++ 获取文件夹下的所有文件名 C++ 获取文件夹下的所有文件名 C++ 获取文件夹下的所有文件名
文件夹压缩文件夹压缩文件夹压缩文件夹压缩
文件文件夹多选对话框。基于MFC的文件选择对话框进行的改造,实现了同时选择多个文件和文件夹的功能。 对于在系统虚拟目录“库”文件夹中进行选择文件和文件夹也做了特殊的处理。 在其他语言(比如c#)中也可以...
本视频为C/C++编程经典项目之C++远程桌面监控系统。主要利用C语言知识以及C++编程知识以及少量算法、数据结构的知识来制作,本视频并不建议完全零基础的小伙伴下载学习,因为其中的语法知识或者代码名词可能会对于零...
采用C++ 编写,只有一个函数。 第一个参数为必填的输入参数,填入待查找的文件夹路径 第二个参数为输出参数,输出匹配到的文件信息(包括文件名,文件路径,和一个对应WIN32_FIND_DATA结构) 地三个参数为可选的输入...