• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Directory structure change notification
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Directory structure change notification


  • Subject: Re: Directory structure change notification
  • From: Andreas Schwarz <email@hidden>
  • Date: Mon, 28 Oct 2002 19:01:17 -0800

Does anyone know if it's possible to receive a notification when a
directory's structure has changed? I need to be notified when a user
adds a file to a specific directory, but I don't want to run a loop
that checks periodically. This seems inefficient.

I had this problem a bit less than a year ago and I don't think anything has changed since... There are a couple semi-functional ways of doing this (NSWorkspace has some notifications and there's some kind of thing in Carbon called FNNotify or something like that, I think) but neither do a very decent job from what I've heard (I couldn't get FNNotify to work at all, even, though I've heard some have had a bit of success with it).

I ended up creating a rather extensive and useful framework for this kind of thing (an older version is on my web site; it's been changed pretty drastically since the first release but I haven't had a chance to update the site yet), but for your case (one directory) it seems like it would be overkill.

What you can do (what my framework does) is periodically stat() the directory using a timer, and check if the directory's modification date has changed since the last time you checked. If so, something inside the directory has changed, and you can reload the contents into your app or whatever you need to do. It really doesn't seem to cause much of a performance hit. In my gBrowser app, even checking dozens of folders, it only causes a *very brief* use of about 3% of the CPU when it checks.

You could go a slightly different route (I think this is the "recommended" method in OS X, and it's what PB seem to do) and check for changes only when your application becomes active. I hope this helps...

Andreas Schwarz
http://homepage.mac.com/schwarz
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: NSComboBox Completion
  • Next by Date: bounds, width & height question
  • Previous by thread: Directory structure change notification
  • Next by thread: Re: Sheets, modal and non-modal
  • Index(es):
    • Date
    • Thread