title: Listing (only) the subfolders within a folder -- Swift 3.0 / iOS 10
body: <p>I'm attempting to get a list of all subfolders within a folder (the app's <code>Documents</code> directory, in the example below).  The code below successfully finds everything in the folder (files + folders both), and also finds the files with the specified <code>.text</code> extension, but I'm failing to narrow the results to <em>just</em> a list of the subdirectories.</p>
  
  <pre><code>let filemgr = FileManager.default
  var dirPaths = filemgr.urls(for: .documentDirectory, in: .userDomainMask)
  myDocumentsDirectory = dirPaths[0]
  
  var r = "Directory Listing:\n------------------\n" // r = will be returned (or displayed in this case)
  
  do {
      let directoryContents = try FileManager.default.contentsOfDirectory(at: myDocumentsDirectory, includingPropertiesForKeys: nil, options: [])
  
      // all files -- works fine
      let allFileNames = directoryContents.map{ $0.deletingPathExtension().lastPathComponent }
      r += "All file names:\n\(allFileNames)\n\n"
  
      // filtering for text files -- also works fine
      let textFiles = directoryContents.filter{ $0.pathExtension == "text" }
      let textFileNames = textFiles.map{ $0.deletingPathExtension().lastPathComponent }
      r += "text file list:\n\(textFileNames)\n\n"
  
      // Look for folders within the folder -- fails, nothing returned            
      let subdirs = directoryContents.filter{ !$0.isFileURL }
      let subdirNames = subdirs.map{ $0.deletingPathExtension().lastPathComponent }
  
      r += "Subdirectories:\n\(subdirNames)\n\n"
      textView.text = r
  
  } catch let error as NSError {
      print(error.localizedDescription)
  </code></pre>
  
  <p>I can pick up all the directories by setting the filter to </p>
  
  <pre><code>$0.pathExtension == ""
  </code></pre>
  
  <p>but that <em>also</em> picks up any files in the directory with no extension -- i.e. it correctly excludes <code>foo.bar</code> but incorrectly includes the file <code>foo</code> along with the folders, and that isn't what I need -- has to be <strong>only</strong> the directories &amp; nothing more.</p>
  
  <p>Also, I'm not trying to look deeper into sub-folders within sub-folders -- just the ones "here" is all I'm looking for.</p>
  
  <p>Any suggestions will be much appreciated!</p>