admin管理员组文章数量:1125588
I want to create a folder in the system's Documents folder like the application CASRER, but it fails。
public extension URL {
static var userHome : URL {
URL(fileURLWithPath: userHomePath, isDirectory: true)
}
static var userHomePath : String {
let pw = getpwuid(getuid())
if let home = pw?.pointee.pw_dir {
return FileManager.default.string(withFileSystemRepresentation: home, length: Int(strlen(home)))
}
fatalError()
}
}
let homeDirectory = URL.userHome
//Music
let documentsDirectory = homeDirectory.appendingPathComponent("Documents")
let newFolderName = "TEST"
let newFolderURL = documentsDirectory.appendingPathComponent(newFolderName)
if !FileManager.default.fileExists(atPath: newFolderURL.path) {
do {
try FileManager.default.createDirectory(at: newFolderURL, withIntermediateDirectories: true, attributes: nil)
print("文件夹创建成功:\(newFolderURL.path)")
} catch {
print("创建文件夹失败: \(error)")
}
} else {
print("文件夹已存在:\(newFolderURL.path)")
}
Error Domain=NSCocoaErrorDomain Code=513 "你没有将文件“TEST”存储到文件夹“文稿”中的权限。" UserInfo={NSFilePath=/Users/peanut/Documents/TEST, NSURL=file:///Users/peanut/Documents/TEST, NSUnderlyingError=0x6000010aee50 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}} auto start register ok
本文标签: macosHow to create a folder in the system documentsStack Overflow
版权声明:本文标题:macos - How to create a folder in the system documents - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736656546a1946269.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论