title: Get all URLs for resources in sub-directory in Swift
body: <p>I am attempting to create an array of URLs for all of the resources in a sub-directory in my iOS app. I can not seem to get to the correct path, I want to be able to retrieve the URLs even if I do not know the names (i.e. I don't want to hard code the file names into the code).</p>
  
  <p>Below is a screen shot of the hierarchy, I am attempting to get all the files in the 'test' folder:
  <a href="https://i.stack.imgur.com/nVWcl.png" rel="noreferrer"><img src="https://i.stack.imgur.com/nVWcl.png" alt="enter image description here"></a></p>
  
  <p>Any help is greatly appreciated, I have attempted to use file manager and bundle main path but to no joy so far.</p>
  
  <p>This is the only code I have currently: </p>
  
  <pre><code>let fileManager = FileManager.default
  let path = Bundle.main.urls(forResourcesWithExtension: "pdf", subdirectory: "Files/test")
  
  print(path)
  </code></pre>
  
  <p>I have also tried this code but this prints all resources, I can't seem to specify a sub-directory:</p>
  
  <pre><code>let fm = FileManager.default
  let path = Bundle.main.resourcePath!
  
  do {
      let items = try fm.contentsOfDirectory(atPath: path)
  
      for item in items {
          print("Found \(item)")
      }
  } catch {
      // failed to read directory – bad permissions, perhaps?
  }
  </code></pre>
  
  <p>Based on an answer from @vadian , The folders were changed from virtual groups to real folders. Using the following code I was able to get a list of resources:</p>
  
  <pre><code>let fileManager = FileManager.default
      let path = Bundle.main.resourcePath
  
      let enumerator:FileManager.DirectoryEnumerator = fileManager.enumerator(atPath: "\(path!)/Files/test")!
      while let element = enumerator.nextObject() as? String {
          if element.hasSuffix("pdf") || element.hasSuffix("jpg") { // checks the extension
              print(element)
          }
      }
  </code></pre>