Creat folders -创建文件夹

来源:互联网 发布:淘宝代画效果图被骗 编辑:程序博客网 时间:2024/06/14 13:50

1。实现

  - (BOOL)createDirectoryAtPath:(NSString *)path withIntermediateDirectories:(BOOL)createIntermediates attributes:(NSDictionary *)attributes error:(NSError **)error

createIntermediates:YES-若path中某一目录不存在,则创建它

                    NO-若path中某一目录不存在,则此方法返回NO,创建失败

                    例如:要创建文件夹.../tmp/data/images,其中,data文件夹不存在,若用YES,则此方法会连带创建data及data下的images;若NO,则创建失败

e.g.

    NSFileManager *fileManager = [[NSFileManager alloc] init];   

    NSString *tempDir = NSTemporaryDirectory();

    NSString *imagesDir = [tempDir stringByAppendingPathComponent:@"images"];

    

    NSError *error = nil;

    if ([fileManager createDirectoryAtPath:imagesDir withIntermediateDirectories:YES attributes:nil error:&error]){       

        NSLog(@"Successfully created the directory");       

    } else {

        NSLog(@"Failed to create the directory. Error = %@", error);

    }

0 0
原创粉丝点击