Class

FileManager.DirectoryEnumerator

An NSDirectoryEnumerator object enumerates the contents of a directory, returning the pathnames of all files and directories contained within that directory. These pathnames are relative to the directory.

Overview

You obtain a directory enumerator using NSFileManager’s enumerator(atPath:) method. For more details, see Low-Level File Management Programming Topics.

An enumeration is recursive, including the files of all subdirectories, and crosses device boundaries. An enumeration does not resolve symbolic links, or attempt to traverse symbolic links that point to directories.

Topics

Getting File and Directory Attributes

var directoryAttributes: [FileAttributeKey : Any]?

A dictionary with the attributes of the directory at which enumeration started.

var fileAttributes: [FileAttributeKey : Any]?

A dictionary with the attributes of the most recently returned file or subdirectory (as referenced by the pathname).

var level: Int

The number of levels deep the current object is in the directory hierarchy being enumerated.

Skipping Subdirectories

func skipDescendents()

Causes the receiver to skip recursion into the most recently obtained subdirectory.

func skipDescendants()

Causes the receiver to skip recursion into the most recently obtained subdirectory.

Relationships

Inherits From

See Also

Discovering Directory Contents

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

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

func contentsOfDirectory(atPath: String)

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

func enumerator(atPath: String)

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

func subpathsOfDirectory(atPath: String)

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

func subpaths(atPath: String)

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