Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of FileSystemWatcher (.NET) in Cocoa

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

like image 280
MobX Avatar asked Jun 30 '09 09:06

MobX


4 Answers

Please have a look at FSEvents.

like image 178
diederikh Avatar answered Oct 21 '22 00:10

diederikh


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.

like image 31
Bryan Traywick Avatar answered Oct 21 '22 00:10

Bryan Traywick


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.

like image 2
Dave DeLong Avatar answered Oct 21 '22 00:10

Dave DeLong


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.

like image 1
Jon Hess Avatar answered Oct 21 '22 01:10

Jon Hess