美文网首页iOS Review
iOS中在沙盒中创建指定文件夹

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

作者: 青梅煮码 | 来源:发表于2018-02-06 10:22 被阅读354次
        //获取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];
        }
    

    相关文章

      网友评论

        本文标题:iOS中在沙盒中创建指定文件夹

        本文链接:https://www.haomeiwen.com/subject/eiawzxtx.html