代码之家  ›  专栏  ›  技术社区  ›  Léster

如何从文件URL获取目录?[副本]

  •  0
  • Léster  · 技术社区  · 7 年前

    The file “glyphs” couldn’t be opened because you don’t have permission to view it
    

    我可以从Finder查看,通过打开面板从同一个应用程序访问。。。隐马尔可夫模型。

    print ("filename <\(filename)>, \(isDirectory ? "Directory" : "File")")
    let urlf = url.appendingPathComponent(filename, isDirectory: isDirectory)
    print( "\(urlf.isFileURL ? "this is a file" : "not a file:") \(urlf)" )
    

    此代码的输出为:

    filename <glyphs>, Directory
    this is a file: file:///Users/lukasz/Documents/ClanTestDesignSpace/masters/ClnNew-BlackUltraExpandedHigh.ufo/glyphs/
    

    URL没问题,我在finder中创建了“copy glyphs as pathname”,并对两者进行了比较:除了最后一个斜杠外,它们完全相同。但不再是目录了 this is a file .

    let fileURLs = try fileManager.contentsOfDirectory(at: urlf, includingPropertiesForKeys: nil)
    

    总是返回错误。 我试图改变 includingPropertiesForKeys: [URLResourceKey.nameKey]

    我检查了沙盒( User Selected File : read/write ). 我还能查些什么?

    0 回复  |  直到 8 年前
        1
  •  2
  •   Dávid Pásztor    8 年前

    从沙盒应用程序中,您无法以编程方式访问任何目录中的文件。一旦启用 User Selected File : read/write NSOpenPanel / NSSavePanel ~/Documents 尝试访问的文件夹。