开发者

How do I create a new folder in Cocoa?

I want to know how I can create a new folder at some directory. How c开发者_开发知识库an I do it? I use NSFileManager.


Yes, you can use the createDirectoryAtPath:withIntermediateDirectories:attributes:error: method of NSFileManager:

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html

[ [ NSFileManager defaultManager ] createDirectoryAtPath: @"/My/Custom/Path" withIntermediateDirectories: YES attributes: nil error: NULL ];


Swift 5

  let path = "/Users/\(NSUserName())/Downloads/custom"
   do {
       try FileManager.default.createDirectory(atPath: path, withIntermediateDirectories: true, attributes: nil)
   } catch{
       print(error)
  }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜