subpaths(atPath:)
Returns an array of strings identifying the paths for all items in the specified directory.
Declaration
func subpaths(atPath path: String) -> [String]?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 subpathsOfDirectory(atPath:) instead.
See Also
Discovering directory contents
contentsOfDirectory(at:includingPropertiesForKeys:options:)contentsOfDirectory(atPath:)enumerator(at:includingPropertiesForKeys:options:errorHandler:)enumerator(atPath:)FileManager.DirectoryEnumeratormountedVolumeURLs(includingResourceValuesForKeys:options:)FileManager.VolumeEnumerationOptionssubpathsOfDirectory(atPath:)