Windows 上有没有类似 inotify 的东西?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3517460/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 07:32:47  来源:igfitidea点击:

Is there anything like inotify on Windows?

windowsinotify

提问by johansson

With the Linux OS, there is the ionotify subsystem which notifies an application of changes to the filesystem.

对于 Linux 操作系统,有一个 ionotify 子系统,它会通知应用程序对文件系统的更改。

However, I am mainly a Windows user, so I was wondering if there is a similar way to monitor filesystem changes?

但是,我主要是 Windows 用户,所以我想知道是否有类似的方法来监视文件系统更改?

采纳答案by nos

See the FindFirstChangeNotificationAPI, or the .NET counterpart FileSystemWatcher

请参阅FindFirstChangeNotificationAPI,或 .NET 对应的FileSystemWatcher

回答by blucz

If you're using .net, use FileSystemWatcher. More info here: http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx

如果您使用.net,请使用FileSystemWatcher. 更多信息:http: //msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx

If you're using C, use FindFirstChangeNotification, FindNextChangeNotification, ReadDirectoryChangesW. More info here: http://msdn.microsoft.com/en-us/library/aa365261(VS.85).aspx

如果您使用C,请使用FindFirstChangeNotification, FindNextChangeNotification, ReadDirectoryChangesW。更多信息:http: //msdn.microsoft.com/en-us/library/aa365261(VS.85).aspx

On OSX, the relevant api is the fseventsapi.

OSX 上,相关的 api 是fseventsapi。

They're all subtly different from one another, and they all have questionable reliability in edge cases. In general, you can't depend on these apis for a complete view of all changes 100% of the time. Most people using file system monitoring combine it with periodic scans to compensate for lost or incomplete information from the push api.

它们彼此之间都略有不同,而且它们在边缘情况下的可靠性都值得怀疑。通常,您不能依赖这些 api 来 100% 地查看所有更改的完整视图。大多数使用文件系统监控的人将其与定期扫描相结合,以补偿来自推送 api 的丢失或不完整的信息。

回答by Eugene

JNotifyor FileMonfrom Microsoft.

来自 Microsoft 的JNotifyFileMon

回答by Peter Krnjevic

A bit late but ...

有点晚了但是...

Windows has a facility similar to OSX events whereby you can monitor events without running an app. The Windows USN Journal keeps track of all file changes. Jeffrey Richter (author of Advanced Windows) wrote a terrific articlewith working samples for MSDN Journal. Update: articlenow from archive.org since MSJ no longer online at MS.

Windows 有一个类似于 OSX 事件的工具,你可以在不运行应用程序的情况下监控事件。Windows USN 日志会跟踪所有文件更改。Jeffrey Richter(Advanced Windows 的作者)写了一篇很棒的文章,其中包含 MSDN Journal 的工作示例。更新文章现在来自 archive.org,因为 MSJ 不再在 MS 在线。

MSDN documentation for USN Change Journals.

USN 变更日志的 MSDN 文档。

USN Change Journals are probably better if you're building applications like backup tools or indexes that need to monitor entire volumes.

如果您正在构建需要监视整个卷的备份工具或索引等应用程序,USN Change Journals 可能会更好。

回答by Phillip Brandon Holmes

FileSystemWatcher() is unreliable mainly due to the fact it's error handling for the watcher buffer is more or less incomplete. Due to a lack of path and detailed error handling information, Microsoft gives you no way to recover or manually poll the working directory.

FileSystemWatcher() 不可靠,主要是因为它对观察者缓冲区的错误处理或多或少是不完整的。由于缺少路径和详细的错误处理信息,Microsoft 无法让您恢复或手动轮询工作目录。

The JNotify for Windows is unreliable as well because this bug ^ derives from win32. JNotify uses win32. So, it's no different than FileSystemWatcher().

Windows 的 JNotify 也不可靠,因为这个 bug ^ 源自 win32。JNotify 使用 win32。因此,它与 FileSystemWatcher() 没有什么不同。

回答by Pharaun

I did a bit of searching, I seem to recall seeing something similar for Windows. There's FileSystemWatcherfor .NET. Its mainly for NT or XP and forward.

我做了一些搜索,我似乎记得在 Windows 上看到过类似的东西。有用于 .NET的 FileSystemWatcher。它主要用于 NT 或 XP 和转发。