在Objective-C /可可中创建文件夹/目录 [英] Create folder/directory in Objective-C/cocoa

查看:178
本文介绍了在Objective-C /可可中创建文件夹/目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码在Objective-C /可可中创建一个文件夹/目录。

  if(![fileManager fileExistsAtPath :目录isDirectory:& isDir])
if(![fileManager createDirectoryAtPath:directory attributes:nil])
NSLog(@Error:Create folder failed%@,directory);

它工作正常,但我得到 creatDirectoryAtPath:属性已被弃用警告信息。
在Cocoa / Objective-c中制作目录构建器的最新方法是什么?



SOLVED



  BOOL isDir; 
NSFileManager * fileManager = [NSFileManager defaultManager];
if(![fileManager fileExistsAtPath:directory isDirectory:& isDir])
if(![fileManager createDirectoryAtPath:directory withIntermediateDirectories:YES attributes:nil error:NULL])
NSLog(@错误:创建文件夹失败%@,目录);


解决方案

发现文件约30秒:



- [NSFileManager createDirectoryAtPath:withIntermediateDirectories:attributes:error:]


I have this code for creating a folder/directory in Objective-C/cocoa.

if(![fileManager fileExistsAtPath:directory isDirectory:&isDir])
        if(![fileManager createDirectoryAtPath:directory attributes:nil])
            NSLog(@"Error: Create folder failed %@", directory);

It works fine, but I got creatDirectoryAtPath:attributes is deprecated warning message. What's the newest way of making a directory builder in Cocoa/Objective-c?

SOLVED

BOOL isDir;
NSFileManager *fileManager= [NSFileManager defaultManager]; 
if(![fileManager fileExistsAtPath:directory isDirectory:&isDir])
    if(![fileManager createDirectoryAtPath:directory withIntermediateDirectories:YES attributes:nil error:NULL])
        NSLog(@"Error: Create folder failed %@", directory);

解决方案

About 30 seconds in the documentation found:

-[NSFileManager createDirectoryAtPath:withIntermediateDirectories:attributes:error:]

这篇关于在Objective-C /可可中创建文件夹/目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆