You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-user@hadoop.apache.org by Shane Butler <sh...@gmail.com> on 2008/11/26 05:04:48 UTC

HDFS directory listing from the Java API?

Hi all,

Can someone pls guide me on how to get a directory listing of files on
HDFS using the java API (0.19.0)?

Regards,
Shane

Re: HDFS directory listing from the Java API?

Posted by Shane Butler <sh...@gmail.com>.
Got it! Thanks Jürgen and Lohit!

On Wed, Nov 26, 2008 at 11:10 PM, Jürgen Broß
<ju...@fu-berlin.de> wrote:
> Hi Shane,
>
> I think what you are looking for is the following:
>
> Path dirPath = new Path("path to dir");
> FileStatus[] files = FileSystem.get(conf).listStatus(dirPath);
>
> Each FileStatus entry in the above array contains a Path reference
> (files[i].getPath()) to the file or directory contained in dirPath.
>
> Greetings,
> Jürgen
>
> Shane Butler wrote:
>>
>> Hi all,
>>
>> Can someone pls guide me on how to get a directory listing of files on
>> HDFS using the java API (0.19.0)?
>>
>> Regards,
>> Shane
>>
>
>
> --
>
>
> Jürgen Broß
> Institute of Computer Science
> Databases and Information Systems
> Freie Universität Berlin
> Takustr. 9
> D-14195 Berlin, Germany
> phone: +49 30 838-75108
> email: juergen.bross@fu-berlin.de
>
>

Re: HDFS directory listing from the Java API?

Posted by Jürgen Broß <ju...@fu-berlin.de>.
Hi Shane,

I think what you are looking for is the following:

Path dirPath = new Path("path to dir");
FileStatus[] files = FileSystem.get(conf).listStatus(dirPath);

Each FileStatus entry in the above array contains a Path reference 
(files[i].getPath()) to the file or directory contained in dirPath.

Greetings,
Jürgen

Shane Butler wrote:
> Hi all,
>
> Can someone pls guide me on how to get a directory listing of files on
> HDFS using the java API (0.19.0)?
>
> Regards,
> Shane
>   


-- 


Jürgen Broß
Institute of Computer Science
Databases and Information Systems
Freie Universität Berlin
Takustr. 9
D-14195 Berlin, Germany
phone: +49 30 838-75108
email: juergen.bross@fu-berlin.de


Re: HDFS directory listing from the Java API?

Posted by lohit <lo...@yahoo.com>.
You can see how 'hadoop dfs -ls' is implemented in FsShell::ls(Path src, boolean recursive, boolean printHeader) in FsShell.java 

Thanks,
Lohit

----- Original Message ----
From: Shane Butler <sh...@gmail.com>
To: hadoop-user@lucene.apache.org
Sent: Tuesday, November 25, 2008 8:04:48 PM
Subject: HDFS directory listing from the Java API?

Hi all,

Can someone pls guide me on how to get a directory listing of files on
HDFS using the java API (0.19.0)?

Regards,
Shane