[ https://issues.apache.org/jira/browse/HDFS-7921?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14359974#comment-14359974 ]
Yi Liu commented on HDFS-7921: ------------------------------ {quote} Is this the intended behavior? It is weird just to list files and not the directories if recursive is set to false. {quote} The behavior is right. {{listFiles}} returns {{RemoteIterator<LocatedFileStatus>}} which includes the block locations of files besides status. So they are different and there is no issue.. > FileSystem listFiles doesn't list the directories if recursive is false > ----------------------------------------------------------------------- > > Key: HDFS-7921 > URL: https://issues.apache.org/jira/browse/HDFS-7921 > Project: Hadoop HDFS > Issue Type: Bug > Affects Versions: 2.5.0 > Reporter: Sowmya Ramesh > > Below code, lists only files and not dirs if recursive is set to false. If > recursive is set to true list all dirs and files. If recursive is set to > false it should behave similar to hadoop fs -ls <path> which is not the case. > {code} > FileSystem fs = FileSystem.get(uri, conf); > RemoteIterator<LocatedFileStatus> fileStatusListIterator = > fs.listFiles(new Path("/tmp"), false); > while(fileStatusListIterator.hasNext()) { > LocatedFileStatus fileStatus = fileStatusListIterator.next(); > System.out.println("Path: " + fileStatus.getPath()); > } > Test results : > Path: hdfs://240.0.0.10:8020/tmp/idtest.hadoopqe.580215.29151.in > Path: hdfs://240.0.0.10:8020/tmp/idtest.hadoopqe.580215.29151.pig > [root@node-1 hive-repl-recipe]# hadoop fs -ls /tmp > Found 4 items > drwx-wx-wx - hadoopqe hdfs 0 2015-03-02 17:52 /tmp/hive > drwxr-xr-x - hadoopqe hdfs 0 2015-03-02 17:51 /tmp/id.out > -rw-r--r-- 3 hadoopqe hdfs 2605 2015-03-02 17:58 > /tmp/idtest.hadoopqe.580215.29151.in > -rw-r--r-- 3 hadoopqe hdfs 159 2015-03-02 17:58 > /tmp/idtest.hadoopqe.580215.29151.pig > {code} > Is this the intended behavior? It is weird just to list files and not the > directories if recursive is set to false. > If listStatus should be used instead can we make listFiles API deprecated? > Thanks! -- This message was sent by Atlassian JIRA (v6.3.4#6332)