Re: Watching folders for new files and event handling based on that?
Re: Watching folders for new files and event handling based on that?
- Subject: Re: Watching folders for new files and event handling based on that?
- From: Gregory Weston <email@hidden>
- Date: Fri, 10 Aug 2007 20:01:55 -0400
Tim Perrett wrote:
Ok interesting. Forgive my ignorance, but a kqueue notifies the
workspace of changes to the file system?
No. The kqueue mechanism lets a process register interest in a
particular file system object, and then when that object changes all
the processes that have registered an interest in it get a callback
triggered. If you register your interest in a directory, you can have
a callback triggered by changes to that directory's contents list.
The functionality im looking for is literally, here is a folder, drop
X file in there which executes Z operation in the application.
Yep. That's exactly what you get. For example say you want to give to
give the user a window that shows them the total size of their trash
can. You register an interest in the file system object ~/.Trash and
then go about your business. Whenever files are added to or removed
from the trash (including by emptying, FWIW) your callback will be
invoked. So you can calculate the current size of the trash contents
and update your display. If you care about what particular files were
added or removed, just keep you own cached list of what you know is
in there, and when your callback is triggered build a new list and
compare it to the old one.
I guess otherwise i'd be down to have a 2nd thread ticking over
occasionally checking the contents of that directory, then going from
there?
Basically that's what using kqueue will do. Except you don't check
periodically. You check when the loop in your thread regains control
from a blocking call. Much more efficient and less code to maintain.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden