- (NSDirectoryEnumerator*) enumeratorAtPath: (NSString*)path
{
return AUTORELEASE([[NSDirectoryEnumerator alloc]
initWithDirectoryPath: path
recurseIntoSubdirectories: YES
followSymlinks: NO
justContents: NO
for: self]);
}
具体实现:
/**
*Initialize instance to enumerate contents at path, which should be a
*directory and can be specified in relative or absolute, and may include
*Unix conventions like '<code>~</code>' for user home directory, which will
*be appropriately converted on Windoze systems.The justContents flag, if
*set, is equivalent to recurseIntoSubdirectories = NO and followSymlinks =
*NO, but the implementation will be made more efficient.
*/
- (id) initWithDirectoryPath: (NSString*)path
recurseIntoSubdirectories: (BOOL)recurse
followSymlinks: (BOOL)follow
justContents: (BOOL)justContents
for: (NSFileManager*)mgr
{
if (nil != (self = [super init]))
{
//TODO: the justContents flag is currently basically useless and should be
//removed
_DIR*dir_pointer;
const _CHAR*localPath;
_mgr = RETAIN(mgr);
_stack = NSZoneMalloc([self zone], sizeof(GSIArray_t));
GSIArrayInitWithZoneAndCapacity(_stack, [selfzone], 64);
_flags.isRecursive = recurse;
_flags.isFollowing = follow;
_flags.justContents = justContents;
_topPath = [[NSString alloc] initWithString: path];
localPath = [_mgrfileSystemRepresentationWithPath: path];
dir_pointer = _OPENDIR(localPath);
if (dir_pointer)
{
GSIArrayItem item;
item.ext.path = @"";
item.ext.pointer = dir_pointer;
GSIArrayAddItem(_stack, item);
}
else
{
NSDebugLog(@"Failed to recurse into directory '%@' - %@", path,
[NSError _last]);
}
}
returnself;
}