Reputation: 46410
I would like to store files in a specific directory inside the documents directory, so that I can iterate over all these files and show them to the user for selection. Is that possible?
Upvotes: 0
Views: 1255
Reputation: 8124
Yups,You can do it like:
NSString *rootString = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) objectAtIndex:0];
self.root = [rootString stringByAppendingPathComponent:@"DirectoryName"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:root isDirectory:YES] == NO)
{
[fileManager createDirectoryAtPath:root attributes:nil];
}
And For retrieving you can do this:
NSError *error;
NSArray *files = [fileManager contentsOfDirectoryAtPath:root error:&error];
Hope this helps,
Thanks, Madhup
Upvotes: 3
Reputation: 523754
Yes.
Use -[NSFileManager createDirectoryAtPath:withIntermediateDirectories:attributes:error:]
.
(The standard POSIX mkdir(2)
also works.)
Upvotes: 1