DEV Community

bsorrentino
bsorrentino

Posted on

Answer: listing all files in a folder recursively with swift

FileManager is right object

If you are using swift 5 or above could take advantage of AsyncStream. Below a simple Playground

import Foundation
import Combine
// Recursive iteration     
func walkDirectory(at url: URL, options: FileManager.DirectoryEnumerationOptions ) -> AsyncStream<URL> {
    AsyncStream { continuation in
        Task {
            let enumerator = FileManager.default.enumerator(at: url,

Top comments (0)