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?
views:
209answers:
2
+1
A:
Yes.
Use -[NSFileManager createDirectoryAtPath:withIntermediateDirectories:attributes:error:]
.
(The standard POSIX mkdir(2)
also works.)
KennyTM
2010-03-16 13:33:10
+3
A:
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
Madhup
2010-03-16 13:45:59
Thanks Madhup. I'm getting an error like "warning: passing argument 2 of 'fileExistsAtPath:isDirectory:' makes pointer from integer without a cast". What does that mean?
dontWatchMyProfile
2010-03-16 15:06:56
@mystify: can you tell me what are you doing?
Madhup
2010-03-17 05:00:52
Can you pls tell whats the variable type of `root` over here?
Suriya
2010-10-13 13:51:09