如何隐藏例如example.app的软件包文件?

时间:2019-06-21 15:26:52

标签: swift xcode macos

我正在OutlineView上列出目录,但是找不到隐藏包文件的方法。

let urls = try FileManager.default.contentsOfDirectory(at: url,                                                                   
                  includingPropertiesForKeys: [.isDirectoryKey],                                                                   
                  options: [.skipsHiddenFiles, .skipsPackageDescendants])

我只能这样跳过常规文件,例如text.txt 列出了所有扩展名为.app的文件

1 个答案:

答案 0 :(得分:1)

skipsPackageDescendants选项旨在防止深入目录遍历将遍历到包中。该标志并不意味着“忽略所有软件包”。这实际上意味着“不要枚举包装内的物品”。

contentsOfDirectory()不会进行深入的目录遍历,因此该选项在这种情况下没有意义。 enumerator(at:...)方法将通过不枚举.app捆绑包中的文件来兑现该标志;它仍然会枚举.app本身。

如果您对某些类型的文件不感兴趣,则可以使用

let urls = try FileManager.default.contentsOfDirectory(
  at: url,
  includingPropertiesForKeys: [.isDirectoryKey],                                                                   
  options: [.skipsHiddenFiles]
).filter { $0.pathExtension != "app" }