views:

100

answers:

1

I'm using UKKQueue to keep an eye on changes to files in a directory. But sometimes there are more directories below the main one and it will not pick up changes to files made in those folders. Therefore I would like to also register those paths to be watched. I can't however get a folder list easily. I can get a list of EVERYTHING using...

[[NSFileManager defaultManager] subpathsOfDirectoryAtPath:@"/Users/rob5408/Documents" error:&error];

...but how can I sift this further to get just directories? I looked at...

- (BOOL)fileExistsAtPath:(NSString *)path isDirectory:(BOOL *)isDirectory;

...but it seems tedious and the boolean pointer really threw me off. Any ideas?

+1  A: 

...but how can I sift this further to get just directories? I looked at...

- (BOOL)fileExistsAtPath:(NSString *)path isDirectory:(BOOL *)isDirectory;

...but it seems tedious and the boolean pointer really threw me off.

A little tedious, but not too hard to use:

BOOL isDir;
if ([mgr fileExistsAtPath:path isDirectory:&isDir] && isDir) {
     //It's a directory
}

You could always make a function (or a category an NSFileManager, as long as you name-tag the method selector appropriately) to wrap this method:

if (R5408_ObjectAtPathIsDirectory(path)) {
     //It's a directory
}

Note that if it isn't a directory, that doesn't mean it's a regular file; one other likely possibility (there are other possibilities) is that it's a symbolic link. Conversely, an alias will appear to be a regular file, but you may be more interested in the original than the alias.

Peter Hosey