Get File List from sub folder of Documents Directory swift ios
<p>I am using this code to get list of PDF files from documents directory.
Now I want to find list of PDF files from Folder named "MyFiles" in Document Directory if that folder exists.</p>

<p>How can I do this??</p>

<pre><code>func listFilesFromDocumentsFolder() -&gt; [String]
{
    var theError = NSErrorPointer()
    let dirs = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.AllDomainsMask, true) as? [String]

    if dirs != nil {
        let dir = dirs![0]
        let fileList = NSFileManager.defaultManager().contentsOfDirectoryAtPath(dir, error: theError) as! [String]
        var count = fileList.count
        for var i = 0; i &lt; count; i++
        {
            var filePath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first as! String
            filePath = filePath.stringByAppendingPathComponent(fileList[i])
            let properties = [NSURLLocalizedNameKey, NSURLCreationDateKey, NSURLContentModificationDateKey, NSURLLocalizedTypeDescriptionKey]
            var attr = NSFileManager.defaultManager().attributesOfItemAtPath(filePath, error: NSErrorPointer())
        }
        return fileList.filter{ $0.pathExtension == "pdf" }.map{ $0.lastPathComponent } as [String]
    }else{
        let fileList = [""]
        return fileList
    }
}
</code></pre>

<p>Thanks in advance..</p>