Is there an method to get the contents of a folder in a particular order? I’d like an array of file attribute dictionaries (or just file names) ordered by date modified.
Right now, I’m doing it this way:
- get an array with the file names
- get the attributes of each file
- store the file’s path and modified date in a dictionary with the date as a key
Next I have to output the dictionary in date order, but I wondered if there’s an easier way? If not, is there a code snippet somewhere which will do this for me?
Thanks.
nall’s code above pointed me in the right direction, but I think there are some mistakes in the code as posted above. For instance:
filesAndPropertiesallocated usingNMutableDictonaryrather than anNSMutableArray?The code above is passing the wrong parameter for
attributesOfItemAtPath– it should beattributesOfItemAtPath:pathfilesarray, but you should be sortingfilesAndProperties.I have implemented the same, with corrections, and using blocks and posted below: