/ Published in: Objective C

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* This is example code of how to walk a directory recurisively and create a flat list of fully qualified names for all the files and directories under the supplied virtual root directory. */ #import <CoreServices/CoreServices.h> #import <AppKit/AppKit.h> #import <stdarg.h> int main (int argc, const char * argv[]) { int result = EXIT_SUCCESS; BOOL isDir; if (dir && ([fm fileExistsAtPath:dir isDirectory:&isDir] && isDir)) { if (![dir hasSuffix:@"/"]) { dir = [dir stringByAppendingString:@"/"]; } // this walks the |dir| recurisively and adds the paths to the |contents| set NSString *f; NSString *fqn; while ((f = [de nextObject])) { // make the filename |f| a fully qualifed filename fqn = [dir stringByAppendingString:f]; if ([fm fileExistsAtPath:fqn isDirectory:&isDir] && isDir) { // append a / to the end of all directory entries fqn = [fqn stringByAppendingString:@"/"]; } [contents addObject:fqn]; } NSString *fn; // here we sort the |contents| before we display them for ( fn in [[contents allObjects] sortedArrayUsingSelector:@selector(compare:)] ) { } } else { result = EXIT_FAILURE; } [pool release]; return result; }
Comments
