【问题标题】:Get the names of files in an iCloud Drive folder that haven't been downloaded yet获取 iCloud Drive 文件夹中尚未下载的文件的名称
【发布时间】:2020-07-21 08:37:09
【问题描述】:

我正在尝试获取 iCloud Drive 目录中所有文件和文件夹的名称:

import Foundation

let fileManager = FileManager.default
let directoryURL = URL(string: "folderPathHere")!

do {
    let directoryContents = try fileManager.contentsOfDirectory(at: directoryURL, includingPropertiesForKeys: nil, options: [.skipsSubdirectoryDescendants, .skipsHiddenFiles])
    for url in directoryContents {
        let fileName = fileManager.displayName(atPath: url.absoluteString)
        print(fileName)
    }
} catch let error {
    let directoryName = fileManager.displayName(atPath: directoryURL.absoluteString)
    print("Couldnt get contents of \(directoryName): \(error.localizedDescription)")
}

似乎任何尚未下载到设备的 iCloud 文件都不会返回 URL。

我知道我可以检查一个路径是否包含一个普遍存在的项目当我已经知道路径时使用下面的代码(即使它没有下载):

fileManager.isUbiquitousItem(at: writePath)

有没有办法在不先下载这些 iCloud 文件的情况下获取它们的 URL 和名称?

目录 URL 是一个安全范围的 URL,由书签数据构成,以防万一(为了清楚起见,此处省略了该代码)。

谢谢

【问题讨论】:

  • 请注意absoluteStringpath不同。你应该使用url.path

标签: ios swift icloud nsfilemanager icloud-drive


【解决方案1】:

找到了答案。我用“.skipsHiddenFiles”跳过隐藏文件,但未下载的文件实际上是隐藏文件,名为:“.fileName.ext.iCloud”。

删除跳过隐藏文件选项现在可以按预期工作。

【讨论】:

    猜你喜欢
    • 2015-08-31
    • 2016-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多