Tuesday, April 23, 2013

NSFileManager subpathsAtPath example ios


subpathsAtPath:

Returns an array of strings identifying the paths for all items in the specified directory.
- (NSArray *)subpathsAtPath:(NSString *)path
Parameters
path
The path of the directory to list.
Return Value of [NSFileManager subpathsAtPath]
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 subpathsAtPath]
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:
Example of [NSFileManager subpathsAtPath]
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];
[fileManager release];