gpt4 book ai didi

swift - 为什么 NSFileManager 不能与 UIDocumentBrowserViewController 一起使用?

转载 作者:行者123 更新时间:2023-11-30 10:55:25 25 4
gpt4 key购买 nike

我需要检查目录中的文件是否存在并且可以打开,但是我的 FileManager.default.fileExists(atPath: <#url_from_uidocumentbrowservc#>)返回假。我无法获取所选目录中的项目列表,无法检查我的项目是否存在。

还有一件事,我想知道所选项目的根目录中包含多少项目。例如,我选择项目文件并想要检查项目目录中包含多少项,然后像项目依赖项一样使用此文件。

查看代码:

func presentDocument(at documentURL: URL) throws {
let rootDirectoryURL = documentURL.deletingLastPathComponent()
let items = try FileManager.default.contentsOfDirectory(at: rootDirectoryURL,
includingPropertiesForKeys: [],
options: []) // Return error `permission denied`
... other code for init document

}

附注URL.startAccessingSecurityScopedResource 也不起作用。

最佳答案

如果想知道根目录下保存了哪些文件:

 override func viewDidLoad() {
super.viewDidLoad()

let fileName = getDocumentsDirectory().appendingPathComponent("fileNameSave")
print(fileName)
// Name of saved path

do {
try .write(to: fileNameZip)
} catch {
print("error")
}
}


func getDocumentsDirectory() -> URL {
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
return paths[0]
}

关于swift - 为什么 NSFileManager 不能与 UIDocumentBrowserViewController 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54012815/

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