---
title: "subpathsOfDirectory(atPath:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/filemanager/subpathsofdirectory(atpath:)"
---

# subpathsOfDirectory(atPath:)

Performs a deep enumeration of the specified directory and returns the paths of all of the contained subdirectories.

## Declaration

```swift
func subpathsOfDirectory(atPath path: String) throws -> [String]
```

## Parameters

- `path`: The path of the directory to list.

## Return Value

Return Value An array of strings, each containing the path of an item in the directory specified by path. When using Objective-C, returns nil if an error occurred.

## Discussion

Discussion This method recurses the specified directory and its subdirectories. The method skips the “.” and “..” directories at each level of the recursion. Because this method recurses the directory’s contents, you might not want to use it in performance-critical code. Instead, consider using the enumeratorAtURL:includingPropertiesForKeys:options:errorHandler: or enumerator(atPath:) method to enumerate the directory contents yourself. Doing so gives you more control over the retrieval of items and more opportunities to complete the enumeration or perform other tasks at the same time. note: In Swift, this method returns a nonoptional result and is marked with the throws keyword to indicate that it throws an error in cases of failure. You call this method in a try expression and handle any errors in the catch clauses of a do statement, as described in Error Handling in The Swift Programming Language and About Imported Cocoa Error Parameters.

## See Also

### Discovering directory contents

- [contentsOfDirectory(at:includingPropertiesForKeys:options:)](foundation/filemanager/contentsofdirectory(at:includingpropertiesforkeys:options:).md)
- [contentsOfDirectory(atPath:)](foundation/filemanager/contentsofdirectory(atpath:).md)
- [enumerator(at:includingPropertiesForKeys:options:errorHandler:)](foundation/filemanager/enumerator(at:includingpropertiesforkeys:options:errorhandler:).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)
- [subpaths(atPath:)](foundation/filemanager/subpaths(atpath:).md)
