質問

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