- Inherits from:
- NSEnumerator : NSObject
- Conforms to:
- NSObject
- (NSObject)
Declared in:
- Foundation/NSFileManager.h
An NSDirectoryEnumerator object enumerates the contents of a directory, returning the pathnames of all files and directories contained within that directory. The pathnames are relative to the directory. This enumeration is recursive, including the files of all subdirectories, and crosses device boundaries. It does not resolve symbolic links or attempt to traverse symbolic links that point to directories.
NSDirectoryEnumerator is an abstract class, a cover for a private concrete subclass tailored to the file system's directory structure. You cannot directly create an instance of NSDirectoryEnumerator-instances are returned only by NSFileManager's enumeratorAtPath: method.
To get the next item from the NSDirectoryEnumerator, invoke the NSEnumerator method nextObject. The methods declared by NSDirectoryEnumerator return attributes-both of the parent directory and the current file or directory-and allow you to control recursion into subdirectories.
The following example enumerates the contents of a directory and processes files; if, however, it comes across RTFD file packages, it skips recursion into them:
NSDirectoryEnumerator *direnum = [[NSFileManager defaultManager] enumeratorAtPath:@"/Sales/Reports"]; NSString *pname; while (pname = [direnum nextObject]) { if ([[pname pathExtension] isEqualToString:@"rtfd"]) { [direnum skipDescendents]; /* don't enumerate this directory */ } else { /* ...process file here... */ } }
- Getting attributes
- - directoryAttributes
- - fileAttributes
- Skipping subdirectories
- - skipDescendents
- (NSDictionary *)directoryAttributes
See Also: - createDirectoryAtPath:attributes: (NSFileManager)
- (NSDictionary *)fileAttributes
- (void)skipDescendents