<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/FileManager/enumerator(atPath:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSFileManager(im)enumeratorAtPath:"
  },
  "title" : "enumerator(atPath:)"
}
-->

# enumerator(atPath:)

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

```
func enumerator(atPath path: String) -> FileManager.DirectoryEnumerator?
```

## Parameters

`path`

The path of the directory to enumerate.

## Return Value

A [`FileManager.DirectoryEnumerator`](/documentation/Foundation/FileManager/DirectoryEnumerator) object that enumerates the contents of the directory at `path`.

## Discussion

If `path` is a filename, the method returns an enumerator object that enumerates no files—the first call to [`nextObject()`](/documentation/Foundation/NSEnumerator/nextObject()) will return `nil`.

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. This method does not resolve symbolic links encountered in the traversal process, nor does it recurse through them if they point to a directory.

This code fragment enumerates the subdirectories and files under a user’s `Documents` directory and processes all files with an extension of `.doc`:

```objc
NSString *docsDir = [NSHomeDirectory() stringByAppendingPathComponent:  @"Documents"];
NSFileManager *localFileManager=[[NSFileManager alloc] init];
NSDirectoryEnumerator *dirEnum =
    [localFileManager enumeratorAtPath:docsDir];
 
NSString *file;
while ((file = [dirEnum nextObject])) {
    if ([[file pathExtension] isEqualToString: @"doc"]) {
        // process the document
        [self scanDocument: [docsDir stringByAppendingPathComponent:file]];
    }
}
```

The [`FileManager.DirectoryEnumerator`](/documentation/Foundation/FileManager/DirectoryEnumerator) class has methods for obtaining the attributes of the existing path and of the parent directory and for skipping descendants of the existing path.

## See Also

[`attributesOfItem(atPath:)`](/documentation/Foundation/FileManager/attributesOfItem(atPath:))

Returns the attributes of the item at a given path.

[`currentDirectoryPath`](/documentation/Foundation/FileManager/currentDirectoryPath)

The path to the program’s current directory.

[`enumeratorAtURL:includingPropertiesForKeys:options:errorHandler:`](/documentation/Foundation/NSFileManager/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.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)