开发者

FindFirstChangeNotification API

开发者 https://www.devze.com 2022-12-26 21:01 出处:网络
I am using FindFirstChangeNotification API to monitor the change开发者_运维百科s happening in a particular folder.But how to exclude a particular file(present in the watching folder) change notificati

I am using FindFirstChangeNotification API to monitor the change开发者_运维百科s happening in a particular folder.But how to exclude a particular file(present in the watching folder) change notification Only.


It works at the directory level, if you want to exclude a specific file then just ignore any notifications about it in you application logic.


Use ReadDirectoryChanges(), it monitors files in a directory tree. ReadDirectoryChanges is basically doing the same thing as FindFirstChangeNotification, FindNextChangeNotification. ReadDirectoryChanges is just more powerful because if you provide the optional callback function to ReadDirectoryChangesW(), you can see which file changed, and why it changed, and then filter in your application logic without overhead of any system call(s) to find which file changed, ...you get this array of structures.

typedef struct _FILE_NOTIFY_INFORMATION {

  DWORD NextEntryOffset;

  DWORD Action;                    // <- reason for the change

  DWORD FileNameLength;

  WCHAR FileName[1];

} FILE_NOTIFY_INFORMATION, *PFILE_NOTIFY_INFORMATION;

FindNextChangeNotification is more like a sledgehammer, you still need to check the folder to see what exactly changed, but it easier to use if you already know which file to hunt for. Findfirst/Next also slightly easier to use in terms of thread waiting/IO completion logic.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号