Enumerating the Contents of a Directory

Sometimes you need to get a list of the contents of a directory. This enumeration process can be accomplished using either the enumeratorAtPath: or the contentsOfDirectoryAtPath:error method. In the former case, each file in the specified directory is enumerated one at a time and, by default, if one of those files is a directory, its contents are also recursively enumerated. During this process, you can dynamically prevent this recursion by sending a skipDescendants message to an enumeration object so that its contents will not be enumerated.

In the case of contentsOfDirectoryAtPath:error:, the contents of the specified directory are enumerated, and the file list is returned in an array by the method. If ...

Get Programming in Objective-C, Sixth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.