Documentation Archive Developer
Search

NSDirectoryEnumerator

Inherits From:
NSEnumerator : NSObject

Conforms To:
NSObject (NSObject)
NSCopying

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 it crosses device boundaries.

NSDirectoryEnumerator is an abstract class, a cover for a private concrete subclass that is tailored to the the file system's directory structure. You cannot directly create an instance of one of these subclasses. 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 cancel 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]
enumeratorWithPath:@"/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:follow: for details on extracting the attributes from the dictionary.


skipDescendents

- (void)skipDescendents

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

Copyright © 1997, Apple Computer, Inc. All rights reserved.