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

2

4

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?

Jodi answered 18/9, 2009 at 3:5 Comment(2)
It occurs to me that I could do this with Spotlight, but I'm looking for a more low-level solution.Jodi
also check out fswatch from this questionLongwinded
A
9

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

Anisometropia answered 18/9, 2009 at 3:13 Comment(1)
Thou rockest, Monsieur Thivent. Thanks.Jodi
T
3

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.

Trainee answered 19/9, 2009 at 4:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.