我无法在应用程序的文件夹(iOS 7)中创建新目录,我使用此代码...
NSFileManager *filemgr;
NSArray *dirPaths;
NSString *docsDir;
NSString *newDir;
filemgr =[NSFileManager defaultManager];
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
docsDir = dirPaths[0];
newDir = [docsDir stringByAppendingPathComponent:@"myPictures"];
在检查日志目录时,它显示了具有新目录的路径名,但是当在finder中检查时,文档目录仍为空。
有什么建议吗?
答案 0 :(得分:2)
试试这个,
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];
}