chacham15
chacham15

Reputation: 14251

How to Monitor Changes in a Directory on Mac OS X?

In the Windows API, when you monitor a directory, the callback provides what changed. How do I accomplish the same for Mac OS X?

I looked at the File System Events API and the Kernel Events API and it seems like they both watch a file descriptor and return what changes happened to that file descriptor. This is inconvenient because now I have to open watchers on the entire file structure and remember the previous names (in case of a rename).

Is there a better way (that doesn't involve a library)?

Upvotes: 4

Views: 3126

Answers (1)

rob mayoff
rob mayoff

Reputation: 385500

FSEvents watches a directory hierarchy (or multiple hierarchies), not a file descriptor. So you only need one watcher. But you will need to scan the directories to find out which files changed. There is no better way (that doesn't involve a library).

Upvotes: 2

Related Questions