gpt4 book ai didi

How do i get the downloads directory's path for iOS through Swift?(如何通过SWIFT获取iOS的下载目录路径?)

转载 作者:bug小助手 更新时间:2023-10-24 22:17:38 25 4
gpt4 key购买 nike



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 {}

更多回答

Does this answer your question? FileManager.contentsEqual returns false when comparing copied files

这回答了你的问题吗?比较复制的文件时,FileManager.contentsEquity返回FALSE

优秀答案推荐

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)

(标记为社区,以便其他人可以改进/澄清)


更多回答

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