views:

419

answers:

1

Hi Everyone:

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?

+5  A: 

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

Martin Gordon
Thanks! It works great! Just asking though, but is that code open source and is it necessary that I give credit?
PF1
Apple's license for code samples is on the longer code samples, and it may apply to the smaller snippets, too. More usefully, if that's a worry, I'd just read the snippet and learn the technique, then write my own original code with that technique.
Peter Hosey