Lucas78
Lucas78

Reputation: 324

list directories and subFolder of project

I want to list directories and subdirectories I created in my application for instance :

-Assets
------Config
------BUILD
------------file.json
------------file2.json
------RUN
------------file3.json

ect

I can't find any method to do that

Upvotes: 0

Views: 39

Answers (1)

Lucas78
Lucas78

Reputation: 324

After some hours of searching I found this solution:

NSURL *myDirectoryURL = [[NSBundle mainBundle] URLForResource:@"Assets" withExtension:@""];
NSDirectoryEnumerator *directoryEnumerator = [[NSFileManager defaultManager] enumeratorAtURL:myDirectoryURL includingPropertiesForKeys:[NSArray array] options:0 errorHandler:^BOOL(NSURL *url, NSError *error) {
    // handle error
    return NO;
}];

NSString *fileOrDirectory = nil;
while ((fileOrDirectory = [directoryEnumerator nextObject])) {
    // use file or directory
    NSLog(@"%@", fileOrDirectory);
}

Upvotes: 1

Related Questions