gpt4 book ai didi

ios - 如何检查目录是否存在?

转载 作者:搜寻专家 更新时间:2023-11-01 06:28:35 24 4
gpt4 key购买 nike

我有创建目录的功能:

func createSystemFolders(){
// Create a FileManager instance
let fileManager = FileManager.default
do {
try fileManager.createDirectory(atPath: "json", withIntermediateDirectories: true, attributes: nil)
}
catch let error as NSError {
debugPrint("\(ErrorsLabels.AppDelegate01): \(error)")
}

do {
try fileManager.createDirectory(atPath: "inspirations", withIntermediateDirectories: true, attributes: nil)
}
catch let error as NSError {
debugPrint("\(ErrorsLabels.AppDelegate02): \(error)")
}

do {
try fileManager.createDirectory(atPath: "products", withIntermediateDirectories: true, attributes: nil)
}
catch let error as NSError {
debugPrint("\(ErrorsLabels.AppDelegate03): \(error)")
}
}

我需要第二个函数来检查目录是否存在。

我如何检查它?

最佳答案

你可以用这个,

fileprivate func directoryExistsAtPath(_ path: String) -> Bool {
var isdirectory : ObjCBool = true
let exists = FileManager.default.fileExists(atPath: path, isDirectory: &isDirectory)
return exists && isDirectory.boolValue
}

关于ios - 如何检查目录是否存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50405920/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com