在我的 macOS 应用程序中,我正在尝试使用以下扩展名创建目录
extension URL {
static func createFolder(folderName: String, folderPath:URL) -> URL? {
let fileManager = FileManager.default
let folderURL = folderPath.appendingPathComponent(folderName)
// If folder URL does not exist, create it
if !fileManager.fileExists(atPath: folderURL.path) {
do {
// Attempt to create folder
// try fileManager.createDirectory(at: folderURL, withIntermediateDirectories: true, attributes: nil)
// try fileManager.createDirectory(atPath: folderURL.path, withIntermediateDirectories: true, attributes: nil)
try fileManager.createDirectory(atPath: folderURL.relativePath, withIntermediateDirectories: true, attributes: nil)
} catch {
print(error.localizedDescription + ":\(folderURL.path)")
return nil
}
}
return folderURL
}
}
当我调用此调用时,它给了我错误
您无权将文件“FolderName”保存在“SelectedFolder”文件夹中。:/Users/USERNAME/Workspace/SelectedFolder/FolderName
我看过一个类似的帖子并尝试了所有方法,但它仍然给我错误,我在这里遗漏了什么吗?任何帮助表示赞赏