Reputation: 3180
I wish to retrieve all filenames from the root directory with the extension *.gs and store them in an array.
I tried using directoryContentsAtPath.. but it says that this method has been deprecated in ios5. Do you know any alternatives?
Upvotes: 0
Views: 65
Reputation: 992
You should use NSFileManager
's:
– contentsOfDirectoryAtPath:error:
(See Apple's documentation on NSFileManager.)
You will end up with something like:
NSString *path = @"your/path";
NSError *error = nil;
NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:&error];
If you feel you don't need to check for a potential error, you may pass nil
for the error
argument. However, I would recommend that you check whether an error occurred and display an appropriate error message in that case. You could do it like so:
if (error) {
// display some error message here
} else {
// process filenames returned by NSFileManager
}
Upvotes: 1