Question

I am wondering how to get a NSFileManager listing to display the results in the order that the Finder sorts them. By default, this code:

NSFileManager *fileManager = [[NSFileManager alloc] init];

NSError *foundErrors = nil;

NSArray *contentsOfDockDirectory = [fileManager contentsOfDirectoryAtPath:@"/Users/me/Desktop error:&foundErrors];

Generates a NSArray that lists it in this type of order: 1, 100, 2, 200, etc. However, the Finder shows it in it's correct sorting so it's: 1, 2, 100, 200, etc.

Is there some way to sort either NSArray or NSFileManager in order to have the listing in this order?

Was it helpful?

Solution

There is a section in the String Programming Guide called "Sorting strings like Finder", which is exactly what you are looking for.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top