Getting a list of files in the Resources folder - iOS

前端 未结 7 2249
悲哀的现实
悲哀的现实 2020-11-28 19:52

Let\'s say I have a folder in my \"Resources\" folder of my iPhone application called \"Documents\".

Is there a way that I can get an array or some type of list of a

7条回答
  •  囚心锁ツ
    2020-11-28 20:36

    Swift

    Updated for Swift 3

    let docsPath = Bundle.main.resourcePath! + "/Resources"
    let fileManager = FileManager.default
    
    do {
        let docsArray = try fileManager.contentsOfDirectory(atPath: docsPath)
    } catch {
        print(error)
    }
    

    Further reading:

    • NSFileManager class reference
    • File System Programming Guide
    • Error Handling docs
    • Error Handling in Swift 2.0 blog post
    • How to find the kind of errors a method may throw and catch them in Swift

提交回复
热议问题