您的位置:首页 > 移动开发 > IOS开发

iOS中在沙盒中创建指定文件夹

2018-02-06 10:19 253 查看
//获取Document文件
NSString * docsdir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString * rarFilePath = [docsdir stringByAppendingPathComponent:@"Announcement"];//将需要创建的串拼接到后面
NSString * dataFilePath = [docsdir stringByAppendingPathComponent:@"AnnouncementData"];
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL isDir = NO;
BOOL dataIsDir = NO;
// fileExistsAtPath 判断一个文件或目录是否有效,isDirectory判断是否一个目录
BOOL existed = [fileManager fileExistsAtPath:rarFilePath isDirectory:&isDir];
BOOL dataExisted = [fileManager fileExistsAtPath:dataFilePath isDirectory:&dataIsDir];
if ( !(isDir == YES && existed == YES) ) {//如果文件夹不存在
[fileManager createDirectoryAtPath:rarFilePath withIntermediateDirectories:YES attributes:nil error:nil];
}
if (!(dataIsDir == YES && dataExisted == YES) ) {
[fileManager createDirectoryAtPath:dataFilePath withIntermediateDirectories:YES attributes:nil error:nil];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐