dontWatchMyProfile
dontWatchMyProfile

Reputation: 46410

How to create an directory inside the documents directory of my iPhone app?

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

Answers (2)

Madhup Singh Yadav
Madhup Singh Yadav

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

Related Questions