How would i go about reading all the files in the downloads directory for iOS?
我该如何开始读取iOS下载目录中的所有文件?
I tried this piece of code but its not printing anything
我试过这段代码,但它没有打印任何东西
do {
try FileManager.default.contentsOfDirectory(
atPath: FileManager.default.urls(for: FileManager.SearchPathDirectory.downloadsDirectory,
in: .allDomainsMask)[0].absoluteString)
.forEach { print($0) }
} catch {}
更多回答
优秀答案推荐
Try?
试一试?
let fileManager = FileManager.default
let downloadsUrl = fileManager.urls(for: .downloadsDirectory, in: .userDomainMask)[0]
do {
if let directoryUrls = try? FileManager.default.contentsOfDirectory(at: downloadsUrl, includingPropertiesForKeys: nil, options: FileManager.DirectoryEnumerationOptions.skipsSubdirectoryDescendants) {
print(directoryUrls)
}
}
I don't think this is GOAT approach, but I've got something similar working for Documents directory, and it seems to be an alt to the sample you provided.
我不认为这是山羊的方法,但我有一些类似的工作文档目录,它似乎是一个替代您提供的样例。
(marked for community so others can improve/clarify)
(标记为社区,以便其他人可以改进/澄清)
更多回答
我是一名优秀的程序员,十分优秀!