【发布时间】:2021-02-20 20:45:26
【问题描述】:
我的 Xcode 目录中有一个黄色文件夹“组”名称“pdfs”。我需要列出文件夹中的所有文件 URL PDF 才能在我的视图中列出。
func listDir(dir: String) {
// Create a FileManager instance
let fileManager = FileManager.default
let documentsURL = fileManager.urls(for: .documentDirectory,
in:.userDomainMask)[0].appendingPathComponent(dir)
do {
let fileUrls = try fileManager.contentsOfDirectory(at:documentsURL, includingPropertiesForKeys: nil)
// process files
print(fileUrls)
} catch {
print("Error while enumerating files \(documentsURL.path): \(error.localizedDescription)")
}
我遇到了这个错误
枚举文件时出错 /Users/user/Library/Developer/CoreSimulator/Devices/EF0F4EB3-CFB0-42F0-B7F5-B36034508BA2/data/Containers/Data/Application/08019A23-FDD9-4FF8-AC1F-2C13CE293BA5 /Documents/pdfs:文件“pdfs”无法打开,因为没有这样的文件。
【问题讨论】:
-
它在你的截图中被命名为
bdfs,而不是pdfs。但是,它们不应该被访问,它们在你的 Bundle 中,所以使用Bundle.main来检索它们。 -
嗯...不看任何其他代码。您拥有屏幕截图的文件夹。显示“bdfs”,而不是“pdfs”
标签: ios swift file-management