title: How to get absolute paths in Hadoop Filesystem?
body: <p>I would like to get a list of all files in a directory and its sub-directories in a HDFS filesystem. This is the method I've written for the purpose of recursively reading all the files in a directory:</p>
  
  <pre><code>def getAllFiles(dir: Path, fs: FileSystem, recursive: Boolean = true): Seq[Path] = {
    val iter = fs.listFiles(dir, recursive)
    val files = new ListBuffer[Path]()
  
    while (iter.hasNext()) {
      val p = iter.next().getPath
        files.append(p)
      }
      files
  }
  </code></pre>
  
  <p>The result is a list of <code>org.apache.hadoop.fs.Path</code> elements which I need to process in the sub-sequent steps. Hence, I need to full path. My question is: what is the best way to get the full absolute path</p>
  
  <p>So far, I use a recursive method to create the path string (Scala):</p>
  
  <pre><code>def fullPath(p: Path): String = {
    if (p.isRoot())
      p.getName
    else
      fullPath(p.getParent) + Path.SEPARATOR + p.getName
  }
  </code></pre>
  
  <p>Is there no more straight-forward way through the Path API?</p>
  
  <p>I've come across question <a href="https://stackoverflow.com/questions/18034758/hadoop-how-to-get-absolute-file-path">#18034758</a>, but using <code>listFiles()</code> rather than <code>listStatus()</code> seems to be the preferred way to recursively list files in a directory so the answer seems a bit cumbersome for this use case.</p>