Instance Method

subpathsOfDirectory(atPath:)

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

Declaration

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

Parameters

path

The path of the directory to list.

Return Value

An array of strings, each containing the path of an item in the directory specified by path.

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 enumerator(at: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.

See Also

Discovering Directory Contents

func contentsOfDirectory(at: URL, includingPropertiesForKeys: [URLResourceKey]?, options: FileManager.DirectoryEnumerationOptions) -> [URL]

Performs a shallow search of the specified directory and returns URLs for the contained items.

func contentsOfDirectory(atPath: String) -> [String]

Performs a shallow search of the specified directory and returns the paths of any contained items.

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

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

class FileManager.DirectoryEnumerator

An object that enumerates the contents of a directory.

func subpaths(atPath: String) -> [String]?

Returns an array of strings identifying the paths for all items in the specified directory.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software