PATH  Documentation > Mac OS X > Foundation Reference: Objective-C



Table of Contents

NSDirectoryEnumerator


Inherits from:
NSEnumerator : NSObject
Conforms to:
NSObject
(NSObject)
Declared in:
Foundation/NSFileManager.h




Class Description


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... */
    }
}




Method Types


Getting attributes
- directoryAttributes
- fileAttributes
Skipping subdirectories
- skipDescendents


Instance Methods



directoryAttributes

- (NSDictionary *)directoryAttributes

Returns an NSDictionary that contains the attributes of the directory at which enumeration started. See the description of NSFileManager's fileAttributesAtPath:traverseLink: for details on obtaining the attributes from the dictionary.

See Also: - createDirectoryAtPath:attributes: (NSFileManager)



fileAttributes

- (NSDictionary *)fileAttributes

Returns an NSDictionary that contains the attributes of the most recently returned file or subdirectory (as referenced by the path name). See the description of NSFileManager's fileAttributesAtPath:traverseLink: for details on extracting the attributes from the dictionary.

skipDescendents

- (void)skipDescendents

Causes the NSDirectoryEnumerator to skip recursion into the most recently obtained subdirectory.


Table of Contents