Cocoa 中 FileSystemWatcher (.NET) 的等效项

发布于 2024-07-25 23:34:48 字数 94 浏览 4 评论 0原文

我正在 Cocoa 中开发一个应用程序。 我想不断检查特定位置的文件内容是否已更改(例如 .NET 中的 FileSystemWatcher)。 请任何人给我一个解决方案

I am developing an application in Cocoa. I want to constantly check whether the contents of a file in a particular location is changed or not (like FileSystemWatcher in .NET). Please anyone give me a solution

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

欢烬 2024-08-01 23:34:48

请查看 FSEvents

Please have a look at FSEvents.

小…楫夜泊 2024-08-01 23:34:48

正如 Diederik 所说, FSEvents 是 Apple 的 Carbon API用于监听文件系统事件。 有人为 FSEvents 创建了一个名为 SCEvents 的 Cocoa/Objective-C 包装器,它有点小更容易使用。

As Diederik says, FSEvents is Apple's Carbon API for listening to file system events. Someone has created a Cocoa/Objective-C wrapper for FSEvents called SCEvents that is a little easier to use.

怀里藏娇 2024-08-01 23:34:48

另一种选择是直接从 /dev/fsevents 消防水管喝水。 我正在开发一个应用程序来完成此任务并且效果非常好。 如果文件发生更改、删除、移动、属性更改等,您会收到通知。当然,这不是“Cocoa”选项,因为它主要是 C 代码,但我们在 Cocoa 应用程序中使用它。

Another option would be to drink directly from the /dev/fsevents firehose. I work on an application that does exactly this and it works very well. You can be notified if a file changes, is deleted, is moved, has attributes changed, etc. Granted, this isn't a "Cocoa" option since it's mostly C code, but we're using this in a Cocoa app.

七分※倦醒 2024-08-01 23:34:48

FSEvents 很棒,但它们用于监视文件夹。 要监视单个文件,您需要查看 kqueues。 在终端中尝试“man kqueue”。

FSEvents are great, but they're used to monitor folders. To monitor a single file you'll want to check out kqueues. Try "man kqueue" in the terminal.

夜灵血窟げ 2024-08-01 23:34:48

查看 NSWorkspace 类文档。

Look at the NSWorkspace class documentation.

暗藏城府 2024-08-01 23:34:48

下面是如何使用书签和 NSFileManager 执行此操作的示例,以便您可以在文件移动时跟踪该文件。

https://github.com/ptrsghr/FileWatcher

Here's an example of how to do it with bookmarks and NSFileManager so that you can follow the file if it's moved.

https://github.com/ptrsghr/FileWatcher

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文