Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Yes. Pass <code>kFSEventStreamCreateFlagWatchRoot</code> as the last argument to <code>FSEventStreamCreate</code>, and you'll be notified if the directory's moved or renamed. From the <a href="https://developer.apple.com/documentation/coreservices/1455376-fseventstreamcreateflags/kfseventstreamcreateflagwatchroot?language=objc" rel="nofollow noreferrer" title="docs">docs</a>:</p> <blockquote> <p>Request notifications of changes along the path to the path(s) you're watching. For example, with this flag, if you watch "/foo/bar" and it is renamed to "/foo/bar.old", you would receive a RootChanged event. The same is true if the directory "/foo" were renamed. The event you receive is a special event: the path for the event is the original path you specified, the flag kFSEventStreamEventFlagRootChanged is set and event ID is zero. RootChanged events are useful to indicate that you should rescan a particular hierarchy because it changed completely (as opposed to the things inside of it changing). If you want to track the current location of a directory, it is best to open the directory before creating the stream so that you have a file descriptor for it and can issue an F_GETPATH fcntl() to find the current path.</p> </blockquote> <p><strong>Edit: adding fcntl example</strong></p> <p>That cocoadev example suggests the author's a bit inexperienced with pointers. The pathIntPointer is not only unnecessary, it's also the cause of your problem. Error checking of the return code from fnctl would have caught it. Here's a revised version of your callback:</p> <pre><code>void fsevents_callback(ConstFSEventStreamRef streamRef, void *userData, size_t numumberOfEvents, void *eventPaths, const FSEventStreamEventFlags eventFlags[], const FSEventStreamEventId eventIds[]) { MyAppController *appController = (MyAppController *)userData; char newPath[ MAXPATHLEN ]; int rc; rc = fcntl( appController.watchedDirectoryFileDescriptor, F_GETPATH, newPath ); if ( rc == -1 ) { perror( "fnctl F_GETPATH" ); return; } NSString *newPathString = [[NSString alloc] initWithUTF8String: newPath ]; NSLog(@"newPathString: %@", newPathString); [ newPathString release ]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload