I am trying to return the list of directories present in an app\'s Documents directory. I am able to get an array containing all files of a given extension (eg .txt files or .pn
Try this:
- (ViewController *) init {
if (self = [super init]) self.title = @"Text Files";
// get the list of all files and directories
NSFileManager *fM = [NSFileManager defaultManager];
fileList = [[fM directoryContentsAtPath:DOCUMENTS_FOLDER] retain];
NSMutableArray *directoryList = [[NSMutableArray alloc] init];
for(NSString *file in fileList) {
NSString *path = [DOCUMENTS_FOLDER stringByAppendingPathComponent:file];
BOOL isDir = NO;
[fM fileExistsAtPath:path isDirectory:(&isDir)];
if(isDir) {
[directoryList addObject:file];
}
}
NSLog(@"%@", directoryList);
return self;
}
Mrueg wrote it all but one thing that
fileList = [[fM directoryContentsAtPath:DOCUMENTS_FOLDER];
Replace by
fileList = [fileManager contentsOfDirectoryAtPath:filePath error:nil];