views:

209

answers:

2

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?

+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
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
@mystify: can you tell me what are you doing?
Madhup
Can you pls tell whats the variable type of `root` over here?
Suriya