Answers for "find file with extension swift"

0

get files with file type swift

let enumerator = FileManager.default.enumerator(atPath: folderPath)
let filePaths = enumerator?.allObjects as! [String]
let txtFilePaths = filePaths.filter{$0.contains(".txt")}
for txtFilePath in txtFilePaths{
    //Here you get each text file path present in folder
    //Perform any operation you want by using its path
}
Posted by: Guest on October-20-2020
0

get files with file type swift

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

}
Posted by: Guest on October-20-2020

Code answers related to "Swift"

Browse Popular Code Answers by Language