Home > AI > IOS > Foundation > FileManager >

enumerator(atPath:)

Returns a directory enumerator object that can be used to perform a deep enumeration of the directory at the specified path.

Example code:

let docsDir = NSHomeDirectory()
let localFileManager = FileManager()
let dirEnum = localFileManager.enumerator(atPath: docsDir)
while let file = dirEnum?.nextObject() as? String {
   print("shark", docsDir.appending("/\(file)"))
}

Example 2: get all system sounds

let localFileManager = FileManager()
    let dirEnum = localFileManager.enumerator(atPath: "/System/Library/Audio/UISounds")
    while let file = dirEnum?.nextObject() as? String {
        print("shark", file)
    }
Related posts:

Leave a Reply