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)
}
精彩评论