📜  获取文件类型为 swift 代码示例的文件

📅  最后修改于: 2022-03-11 15:01:01.550000             🧑  作者: Mango

代码示例2
let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
let url = URL(fileURLWithPath: documentsPath)

let fileManager = FileManager.default
let enumerator: FileManager.DirectoryEnumerator = fileManager.enumerator(atPath: url.path)!
while let element = enumerator.nextObject() as? String, element.hasSuffix(".txt") {
    // do something

}