I am trying to return a list of directories present in the application directory. I can get an array containing all files of this extension (for example, .txt or .png files) and I can return all the contents (including directories). The problem occurs when I want to return only directories. Is there an easy way to do this?
Here is my code for returning all .txt files:
- (ViewController *) init { if (self = [super init]) self.title = @"Text Files"; // get the list of .txt files directoryList = [[[[NSFileManager defaultManager] directoryContentsAtPath:DOCUMENTS_FOLDER] pathsMatchingExtensions:[NSArray arrayWithObjects:@".txt", nil]] retain]; NSLog(@"%@", directoryList); return self; }
and for all files
- (ViewController *) init { if (self = [super init]) self.title = @"Text Files"; // get the list of all files and directories directoryList = [[[NSFileManager defaultManager] directoryContentsAtPath:DOCUMENTS_FOLDER] retain]; NSLog(@"%@", directoryList); return self; }
iphone nsfilemanager
Jack
source share