FindFirstChangeNotification 是用于 Windows 上文件系统更改通知的最佳 API 吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16615/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is FindFirstChangeNotification the best API to use for file system change notification on windows?
提问by Free Wildebeest
I'm new to windows programming and I'm trying to get notified of all changes to the file system (similar to the information that FileMon from SysInternals displays, but via an API). Is a FindFirstChangeNotification for each (non-network, non-substed) drive my best bet or are there other more suitable C/C++ APIs?
我是 Windows 编程的新手,我正在尝试获得对文件系统的所有更改的通知(类似于来自 SysInternals 的 FileMon 显示的信息,但通过 API)。我最好的选择是每个(非网络、非substed)驱动器的 FindFirstChangeNotification 还是其他更合适的 C/C++ API?
回答by Mat Noguchi
FindFirstChangeNotification
is fine, but for slightly more ultimate power you should be using ReadDirectoryChangesW.
(In fact, it's even recommended in the documentation!)
FindFirstChangeNotification
很好,但为了获得更多的终极力量,你应该使用ReadDirectoryChangesW.
(事实上,它甚至在文档中被推荐!)
It doesn't require a function pointer, it does require you to manually decode a raw buffer, it uses Unicode file names, but it is generally better and more flexible.
它不需要函数指针,它需要您手动解码原始缓冲区,它使用 Unicode 文件名,但它通常更好更灵活。
On the other hand, if you want to do what FileMon does, you should probably do what FileMon does and use IFS to create and install a file system filter.
另一方面,如果您想做 FileMon 所做的事情,您可能应该做 FileMon 所做的事情并使用IFS 创建和安装文件系统过滤器。
回答by TheSmurf
There are other ways to do it, but most of them involve effort on your part (or take performance from your app, or you have to block a thread to use them, etc). FindFirstChangeNotification is a bit complicated if you're not used to dealing with function pointers, etc, but it has the virtue of getting the OS to do the bulk of the work for you.
还有其他方法可以做到这一点,但其中大部分都需要您的努力(或者从您的应用程序中获取性能,或者您必须阻止一个线程才能使用它们等)。如果您不习惯处理函数指针等,FindFirstChangeNotification 会有点复杂,但它的优点是让操作系统为您完成大部分工作。
回答by TheSmurf
Actually FileSystemWatcher works perfectly with shared network drives. I am using it right now in an application which, among other things, monitors the file system for changes. (www.tabbles.net).
实际上 FileSystemWatcher 与共享网络驱动器完美配合。我现在正在一个应用程序中使用它,其中包括监视文件系统的更改。(www.tabbles.net)。
回答by UBpine Inc
You can use FileSystemWatcher class. Very efficient but cannot work with Network shared drives.
您可以使用 FileSystemWatcher 类。非常有效,但不能与网络共享驱动器一起使用。