开发者

Directories under a path in Objective-C

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 *)isDirector开发者_如何学Goy;

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


...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 on 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜