我想使用以下代码创建一个目录,但是它会导致错误“文件无法退出”。当然,它不存在,因为我想创建它。
let dirName:String="test2"
let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let dataPath = documentsDirectory.appendingPathComponent(dirName,isDirectory: true)
do {
try FileManager.default.createDirectory(atPath: dataPath.absoluteString, withIntermediateDirectories: false, attributes: nil)
print("OK")
} catch let error as NSError {
print("Error creating directory: \(error.description)")
}
错误:
Error creating directory: Error Domain=NSCocoaErrorDomain Code=4
"Le fichier « test2 » n’existe pas." (Translation: The file « test2 » does not exist)
UserInfo={NSFilePath=file:///var/mobile/Containers/Data/Application/C91525D0-04D2-47A3-BC00-E75D1B616A73/Documents/test2/,
NSUnderlyingError=0x12fee48c0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
如何创建目录?