How to list all files in a directory and its subdirectories in hadoop hdfs

后端 未结 9 1074
故里飘歌
故里飘歌 2020-12-01 05:50

I have a folder in hdfs which has two subfolders each one has about 30 subfolders which,finally,each one contains xml files. I want to list all xml files giving only the mai

9条回答
  •  囚心锁ツ
    2020-12-01 06:16

    You'll need to use the FileSystem object and perform some logic on the resultant FileStatus objects to manually recurse into the subdirectories.

    You can also apply a PathFilter to only return the xml files using the listStatus(Path, PathFilter) method

    The hadoop FsShell class has examples of this for the hadoop fs -lsr command, which is a recursive ls - see the source, around line 590 (the recursive step is triggered on line 635)

提交回复
热议问题