Instance Method


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


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



The path of the directory to list.

Return Value

An array of NSString objects, each of which contains the path of an item in the directory specified by path. If path is a symbolic link, this method traverses the link. This method returns nil if it cannot retrieve the device of the linked-to file.


This method recurses the specified directory and its subdirectories. The method skips the “.” and “..” directories at each level of the recursion.

This method reveals every element of the subtree at path, including the contents of file packages (such as apps, nib files, and RTFD files). This code fragment gets the contents of /System/Library/Fonts after verifying that the directory exists:

BOOL isDir = NO;
NSArray *subpaths;
NSString *fontPath = @"/System/Library/Fonts";
NSFileManager *fileManager = [[NSFileManager alloc] init];
if ([fileManager fileExistsAtPath:fontPath isDirectory:&isDir] && isDir)
    subpaths = [fileManager subpathsAtPath:fontPath];

Special Considerations

In macOS 10.5 and later, use subpathsOfDirectory(atPath:) instead.

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 subpathsOfDirectory(atPath: String) -> [String]

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