3

I have some folders and subfolders in my documents directory how can i get an array with the files in the directories and subdirectories not the folders just the files.

here is my code so far and it's working if no folders and subfolders exist

//getting all the files on documents folder in an array.
    NSError * error;
    NSArray * directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:&error];
4

2 に答える 2

2
NSFileManager *fileManager = [NSFileManager defaultManager];
NSDirectoryEnumerator *enumerator = [fileManager enumeratorAtPath:documentsDirectory];
NSMutableArray *files = [NSMutableArray array];
BOOL isDirectory;
NSString *path;
while (path = [enumerator nextObject]) {
    if ([fileManager fileExistsAtPath:path isDirectory:&isDirectory] && !isDirectory) {
        [files addObject:path];
    }
}
于 2012-12-04T17:30:30.073 に答える