1

私の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

同様の投稿を見て、すべての方法を試しましたが、それでもエラーが発生します。何か不足していますか? どんな助けでも大歓迎です

4

1 に答える 1