individualtermite
individualtermite

Reputation: 3775

Sort NSFileManager Results

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?

Upvotes: 3

Views: 2171

Answers (1)

Martin Gordon
Martin Gordon

Reputation: 36399

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

Upvotes: 12

Related Questions