Instance Method

subpathsAtPath:

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

Declaration

- (NSArray<NSString *> *)subpathsAtPath:(NSString *)path;

Parameters

path

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.

Discussion

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 subpathsOfDirectoryAtPath:error: instead.

See Also

Discovering Directory Contents

contentsOfDirectoryAtURL:includingPropertiesForKeys:options:error:

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

contentsOfDirectoryAtPath:error:

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

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.

enumeratorAtPath:

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

NSDirectoryEnumerator

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.

mountedVolumeURLsIncludingResourceValuesForKeys:options:

Returns an array of URLs that identify the mounted volumes available on the device.

subpathsOfDirectoryAtPath:error:

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