获取Swift中文档目录下的所有“*.xxx”文件 4
Get all the "*.xxx" files in the document directory in Swift 4
我正在查看 Swift 4 中的 NSFileManager.h
dox,自从我上次使用它以来它似乎发生了变化(变得更好了!)。
我想知道 contentsOfDirectoryAtURL:includingPropertiesForKeys
、url
或 enumeratorAtURL:includingPropertiesForKeys
是否提供了一种枚举特定类型文件的方法,在我的例子中是图像?
我看了很多 Swift 2 个答案,他们都建议循环检查名称,我想确定他们没有 "fixed" 这个,我只是被 API?
搞糊涂了
只是 filter
由 pathExtension
返回的 URLs
do {
let documentsURL = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
let docs = try FileManager.default.contentsOfDirectory(at: documentsURL, includingPropertiesForKeys: nil, options: .skipsHiddenFiles)
let images = docs.filter{ [=10=].pathExtension == "xxx" }
print(images)
} catch {
print(error)
}
我正在查看 Swift 4 中的 NSFileManager.h
dox,自从我上次使用它以来它似乎发生了变化(变得更好了!)。
我想知道 contentsOfDirectoryAtURL:includingPropertiesForKeys
、url
或 enumeratorAtURL:includingPropertiesForKeys
是否提供了一种枚举特定类型文件的方法,在我的例子中是图像?
我看了很多 Swift 2 个答案,他们都建议循环检查名称,我想确定他们没有 "fixed" 这个,我只是被 API?
搞糊涂了只是 filter
由 pathExtension
URLs
do {
let documentsURL = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
let docs = try FileManager.default.contentsOfDirectory(at: documentsURL, includingPropertiesForKeys: nil, options: .skipsHiddenFiles)
let images = docs.filter{ [=10=].pathExtension == "xxx" }
print(images)
} catch {
print(error)
}