title: Traversing mounted volumes to find specific file types
body: <p>I am trying to figure out how to scan mounted volumes (they are attached to a server and they are mounted via afp:// onto my workstation) and pick out certain files types, and output the path, file name and asset id to a csv file. The asset id is the last 10 digits of the file name preceded by an "_" ( for example: <strong>afilename_1234567890.mov</strong>) Some files do not have an asset id (I ignore) and some files have multiple "."'s (for example, <strong>afilename_videofile_23.98_prores_1234567890.mov</strong>). I can get the volumes I need (less a time machine backup drive) but trying to scan for the files is troublesome. I have looked a various example and studied the Apple FileManager docs but there is nothing concrete.</p>
  
  <p>I have the following routine to do what I need but with the line, <strong>let enumerator = fileManager.enumerator(atPath: url.path)!</strong>, enumerator is always blank.</p>
  
  <p>Either I am making a bad assumption or I am definitely missing something crucial.</p>
  
  <pre><code>func FindFilesWithAssetIDs() {
  
      // Find all the mounted volumes
      let keys: [URLResourceKey] = []
      let volumes = FileManager.default.mountedVolumeURLs(includingResourceValuesForKeys: keys, options: [])!
  
      var count = 0
      var volumeCount = volumes.count
      var volumeItem = 0
  
      let filterExtensions = ["mxf", "mov", "mp4", "scc", "cap", "srt", "txt", "rtf", "wav", "mp3", "m2v", "aif"]
  
      // Scan all the mounted volumes, one at a time
      for url in volumes {
  
          let components = url.pathComponents
  
          if components.count &gt; 1  &amp;&amp; components[1] == "Volumes" {
              if components[2] == "Time Machine Backup" { continue } // Check if the volume is the staff backup disk. If it is, move on to the next volume
  
              guard let volumeTypeKey = try? url.resourceValues(forKeys: [.volumeIsLocalKey]) else { return } // Make sure we are scanning the volumes and not any local folders like /private
  
              let volumeType: Bool = volumeTypeKey.volumeIsLocal!
  
              if volumeType == false {
                  let fileManager = FileManager.default
                  let enumerator = fileManager.enumerator(atPath: url.path)!
  
                  while let element = enumerator.nextObject() as? String {
                      if element.hasSuffix("mxf") || element.hasSuffix("mov") { // a test. I would much rather use a filterExtension method or a switch statement
                          // do something
                          count += 1
                      }
                  }
  
                  NSLog(url.path, " ", String(count))
                  //                    NSLog(url.path)
              }
          }
  
          volumeItem += 1
      }
  }
  </code></pre>
  
  <p>Any help would be greatly appreciated.</p>