subpathsOfDirectoryAtPath :error:
Performs a deep enumeration of the specified directory and returns the paths of all of the contained subdirectories.
Parameters
- path
- The path of the directory to list.
- error
- If an error occurs, upon return contains an
NSError
object that describes the problem. PassNULL
if you do not want error information.
Return Value of [NSFileManager subpathsOfDirectoryAtPath]
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 of [NSFileManager subpathsOfDirectoryAtPath]
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
enumeratorAtURL:includingPropertiesForKeys:options:errorHandler:
orenumeratorAtPath:
method to enumerate the directory contents yourself. Doing so gives you more control over the retrieval of items and more opportunities to abort the enumeration or perform other tasks at the same time.
Example of [NSFileManager subpathsOfDirectoryAtPath]
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSArray *filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:documentsDirectory error:nil];
NSLog(@"files array %@", filePathsArray);