mra*_*hay 6 nsfilemanager ios icloud swift icloud-drive
I\xe2\x80\x99m 尝试获取 iCloud Drive 目录中所有文件和文件夹的名称:
\n\nimport Foundation\n\nlet fileManager = FileManager.default\nlet directoryURL = URL(string: "folderPathHere")!\n\ndo {\n let directoryContents = try fileManager.contentsOfDirectory(at: directoryURL, includingPropertiesForKeys: nil, options: [.skipsSubdirectoryDescendants, .skipsHiddenFiles])\n for url in directoryContents {\n let fileName = fileManager.displayName(atPath: url.absoluteString)\n print(fileName)\n }\n} catch let error {\n let directoryName = fileManager.displayName(atPath: directoryURL.absoluteString)\n print("Couldnt get contents of \\(directoryName): \\(error.localizedDescription)")\n}\nRun Code Online (Sandbox Code Playgroud)\n\n似乎任何尚未下载到设备的 iCloud 文件都不会返回 URL。
\n\n我知道当我已经知道带有下面代码的路径时,我可以检查路径是否包含普遍存在的项目(即使它没有下载\xe2\x80\x99t):
\n\nfileManager.isUbiquitousItem(at: writePath)\nRun Code Online (Sandbox Code Playgroud)\n\n有没有办法在不先下载的情况下获取这些 iCloud 文件的 URL 和名称?
\n\n目录 URL 是一个安全范围的 URL,由书签数据构造而成,以防产生任何差异(为清楚起见,此处省略了该代码)。
\n\n谢谢
\n找到了答案。我用“.skipsHiddenFiles”跳过隐藏文件,但未下载的文件实际上是隐藏文件,名为:“.fileName.ext.iCloud”。
删除跳过隐藏文件选项现在可以按预期工作。
| 归档时间: |
|
| 查看次数: |
1150 次 |
| 最近记录: |