How can I receive notifications of filesystem changes in OS X?

眉间皱痕 提交于 2019-12-05 07:21:35

问题


In Windows, I can use the FindNextChangeNotification API to watch a file or folder for changes. For example, I can watch a folder and get notified when a file is added or removed.

Is there a similar API on OS X?


回答1:


Mac OS X v10.5 introduces the File System Events API. Have a look at:

  • Technology Overview
  • Using the File System Events API
  • File System Events Programming Guide (PDF)



回答2:


FSEvents is nice, but for watching just a small set of files or folders it's rather overkill, and it does require Leopard or newer. (The underlying technology was introduced in Tiger, but the API wasn't public.)

As a possible alternative, note that OS X inherits kqueue from FreeBSD (at least as of Panther). You can search for examples of EVFILT_VNODE usage, that's what you want to use to watch for file alterations.



来源:https://stackoverflow.com/questions/1442408/how-can-i-receive-notifications-of-filesystem-changes-in-os-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!