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 Ananth Sarathy <an...@gmail.com> on 2010/10/20 22:17:20 UTC
Size of Directory in HDFS
I am trying to see how what the total size of all the files within a
directory in HDFS is. I try
Configuration conf = new Configuration();
Path inFile = new Path(
"/MyDir");
FileSystem fs = inFile.getFileSystem(conf);
FileStatus status = fs.getFileStatus(inFile);
System.out.println(status.isDir());
System.out.println(status.getLen());
But since it's a directory, i get a 0. Anyone have any idea on how I can get
this info? I am using apache hadoop 20.2.
Secondly, I assume FileSystem.getUsed and FileStatus.getLen is in bytes,
correct?
Ananth T Sarathy
Re: Size of Directory in HDFS
Posted by Harsh J <qw...@gmail.com>.
It should be doable like this:
FileSystem.getContentSummary(FileStatus.getPath()).getLength();
On Thu, Oct 21, 2010 at 1:47 AM, Ananth Sarathy
<an...@gmail.com> wrote:
> I am trying to see how what the total size of all the files within a
> directory in HDFS is. I try
>
> Configuration conf = new Configuration();
>
> Path inFile = new Path(
> "/MyDir");
>
> FileSystem fs = inFile.getFileSystem(conf);
>
>
> FileStatus status = fs.getFileStatus(inFile);
>
> System.out.println(status.isDir());
> System.out.println(status.getLen());
>
>
> But since it's a directory, i get a 0. Anyone have any idea on how I can get
> this info? I am using apache hadoop 20.2.
>
> Secondly, I assume FileSystem.getUsed and FileStatus.getLen is in bytes,
> correct?
>
> Ananth T Sarathy
>
--
Harsh J
www.harshj.com
Re: Size of Directory in HDFS
Posted by Harsh J <qw...@gmail.com>.
> Secondly, I assume FileSystem.getUsed and FileStatus.getLen is in bytes,
> correct?
Yes, this is correct. Lengths of files are returned in bytes.
--
Harsh J
www.harshj.com