Вопрос

I am not able to create a new directory in my application's folder (iOS 7), Am using this code...

    NSFileManager *filemgr;
    NSArray *dirPaths;
    NSString *docsDir;
    NSString *newDir;

    filemgr =[NSFileManager defaultManager];

    dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                   NSUserDomainMask, YES);

    docsDir = dirPaths[0];
    newDir = [docsDir stringByAppendingPathComponent:@"myPictures"];

when checking the log directory it shows path name with the new directory, but when checking in finder the documents directory remains empty.

Any suggestions?

Это было полезно?

Решение

Try this,

NSFileManager *filemgr;
NSArray *dirPaths;
NSString *docsDir;
NSString *newDir;

filemgr =[NSFileManager defaultManager];

dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                               NSUserDomainMask, YES);

docsDir = dirPaths[0];
newDir = [docsDir stringByAppendingPathComponent:@"/myPictures"];
if(![filemgr fileExistsAtPath:newDir])
{
    NSData *data = [NSData dataWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/myPictures"]];
    NSError *error;
    [[NSFileManager defaultManager] createDirectoryAtPath:[docsDir stringByAppendingPathComponent:@"/myPictures"] withIntermediateDirectories:YES attributes:nil error:&error];
    [data writeToFile:newDir atomically:YES];
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top