swift - 如何隐藏像example.app这样的包文件?
问题描述
我在大纲视图上列出目录,但找不到隐藏包文件的方法。
let urls = try FileManager.default.contentsOfDirectory(at: url,
includingPropertiesForKeys: [.isDirectoryKey],
options: [.skipsHiddenFiles, .skipsPackageDescendants])
我只能跳过常规文件,如 text.txt 列出所有扩展名为 .app 的文件
解决方案
该skipsPackageDescendants
选项旨在防止深度目录遍历进入包。该标志并不意味着“忽略所有包”。它实际上意味着“不要枚举包内的内容”。
contentsOfDirectory()
不会进行深度目录遍历,因此该选项在该上下文中毫无意义。该enumerator(at:...)
方法将通过不枚举包中的文件来尊重该标志.app
;它仍然会枚举.app
自身。
如果您对某些类型的文件不感兴趣,您可以使用
let urls = try FileManager.default.contentsOfDirectory(
at: url,
includingPropertiesForKeys: [.isDirectoryKey],
options: [.skipsHiddenFiles]
).filter { $0.pathExtension != "app" }
推荐阅读
- php - 将 SQL 转换为 Laravel 查询生成器错误 - 需要专家级别
- substrate - Make Init bash: mingw-get: command not found
- javascript - React.JS:如何制作存储在公共文件夹中的图像的表单数据
- reactjs - 导致错误的 react-redux v6 和 v7 之间的区别?
- spring - 在 spark 数据帧上调用 show 方法后,我看不到 spring boot/spark 应用程序中显示的数据
- sapui5 - 刷新后如何获取 TwoColumnsMidExpanded
- google-bigquery - Bigquery 用一些 000 替换空结果或空值
- performance - 如何在 Jmeter 中生成 AWS Cognito Bearer 令牌?
- c++ - 如何使用 boost 库获取谷歌海拔 api?
- css - 禁用/启用时输入背景颜色变化