HDFS: How do you list files recursively?

wsb3383 picture wsb3383 · Jun 8, 2012 · Viewed 24.8k times · Source

How do you, through Java, list all files (recursively) under a certain path in HDFS. I went through the API and noticed FileSystem.listFiles(Path,boolean) but it looks like that method doesn't exist in my instance of FileSystem when I initialize it.

Answer

Chris White picture Chris White · Jun 8, 2012

You can look at the source for org.apache.hadoop.fs.FsShell.ls(FileStatus, FileSystem, boolean, boolean) for your version of hadoop - this is what is called when you perform a hadoop fs -lsr path from the command line