---
title: "enumeratorAtURL:includingPropertiesForKeys:options:errorHandler:"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsfilemanager/enumeratoraturl:includingpropertiesforkeys:options:errorhandler:"
---

# enumeratorAtURL:includingPropertiesForKeys:options:errorHandler:

Returns a directory enumerator object that can be used to perform a deep enumeration of the directory at the specified URL.

## Declaration

```occ
- (NSDirectoryEnumerator<NSURL *> *) enumeratorAtURL:(NSURL *) url includingPropertiesForKeys:(NSArray<NSString *> *) keys options:(NSDirectoryEnumerationOptions) mask errorHandler:(BOOL (^)(NSURL *url, NSError *error)) handler;
```

## Parameters

- `url`: The location of the directory for which you want an enumeration. This URL must not be a symbolic link that points to the desired directory. You can use the doc://com.apple.foundation/documentation/Foundation/NSURL/resolvingSymlinksInPath method to resolve any symlinks in the URL.
- `keys`: An array of keys that identify the properties that you want pre-fetched for each item in the enumeration. The values for these keys are cached in the corresponding doc://com.apple.foundation/documentation/Foundation/NSURL objects. You may specify nil for this parameter. For a list of keys you can specify, see doc://com.apple.foundation/documentation/Foundation/URLResourceKey.
- `mask`: Options for the enumeration. For a list of valid options, see doc://com.apple.foundation/documentation/Foundation/FileManager/DirectoryEnumerationOptions.
- `handler`: An optional error handler block for the file manager to call when an error occurs. The handler block should return doc://com.apple.documentation/documentation/Swift/true if you want the enumeration to continue or doc://com.apple.documentation/documentation/Swift/false if you want the enumeration to stop. The block takes the following parameters: If you specify nil for this parameter, the enumerator object continues to enumerate items as if you had specified a block that returned doc://com.apple.documentation/documentation/Swift/true.

## Return Value

Return Value An directory enumerator object that enumerates the contents of the directory at url. If url is a filename, the method returns an enumerator object that enumerates no files—the first call to nextObject() returns nil.

## Discussion

Discussion Because the enumeration is deep—that is, it lists the contents of all subdirectories—this enumerator object is useful for performing actions that involve large file-system subtrees. If the method is passed a directory on which another file system is mounted (a mount point), it traverses the mount point. This method does not resolve symbolic links or mount points encountered in the enumeration process, nor does it recurse through them if they point to a directory. For example, if you pass a URL that points to /Volumes/MyMountedFileSystem, the returned enumerator will include the entire directory structure for the file system mounted at that location. If, on the other hand, you pass /Volumes, the returned enumerator will include /Volumes/MyMountedFileSystem as one of its results, but will not traverse into the file system mounted there. The FileManager.DirectoryEnumerator class has methods for skipping descendants of the existing path and for returning the number of levels deep the current object is in the directory hierarchy being enumerated (where the directory passed to enumeratorAtURL:includingPropertiesForKeys:options:errorHandler: is considered to be level 0). This code fragment enumerates a URL and its subdirectories, collecting the URLs of files (skips directories). It also demonstrates how to ignore the contents of specified directories, in this case directories named “_extras”. NSURL *directoryURL = [[NSBundle mainBundle] bundleURL]; NSFileManager *localFileManager= [[NSFileManager alloc] init]; NSDirectoryEnumerator *directoryEnumerator =    [localFileManager enumeratorAtURL:directoryURL           includingPropertiesForKeys:@[NSURLNameKey, NSURLIsDirectoryKey]                              options:NSDirectoryEnumerationSkipsHiddenFiles                         errorHandler:nil];   NSMutableArray<NSURL *> *mutableFileURLs = [NSMutableArray array]; for (NSURL *fileURL in directoryEnumerator) {     NSNumber *isDirectory = nil;     [fileURL getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:nil];       if ([isDirectory boolValue]) {         NSString *name = nil;         [fileURL getResourceValue:&name forKey:NSURLNameKey error:nil];           if ([name isEqualToString:@"_extras"]) {             [directoryEnumerator skipDescendants];         } else {             [mutableFileURLs addObject:fileURL];         }     } }   NSLog(@"Files: %@", mutableFileURLs);

## See Also

### Discovering directory contents

- [contentsOfDirectory(at:includingPropertiesForKeys:options:)](foundation/filemanager/contentsofdirectory(at:includingpropertiesforkeys:options:).md)
- [contentsOfDirectory(atPath:)](foundation/filemanager/contentsofdirectory(atpath:).md)
- [enumerator(atPath:)](foundation/filemanager/enumerator(atpath:).md)
- [FileManager.DirectoryEnumerator](foundation/filemanager/directoryenumerator.md)
- [mountedVolumeURLs(includingResourceValuesForKeys:options:)](foundation/filemanager/mountedvolumeurls(includingresourcevaluesforkeys:options:).md)
- [FileManager.VolumeEnumerationOptions](foundation/filemanager/volumeenumerationoptions.md)
- [subpathsOfDirectory(atPath:)](foundation/filemanager/subpathsofdirectory(atpath:).md)
- [subpaths(atPath:)](foundation/filemanager/subpaths(atpath:).md)
