The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
April 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Re : size of a directory

Posted by Pierre on June 20, 2001 at 2:57 AM

> hello,
> Can any body tell me plz how to find size of a directory(in bytes).The directory may contain sub-directories. Thanx in advance

> saddy

private long getDirSize(File path) {
Iterator path_iterator;
File current_file ;
long size;

path_iterator =
(Arrays.asList(path.listFiles))).iterator();

size=0;

while (path_iterator.hasNext()) {
current_file=(File) path_iterator.next();
if (current_file.isFile()) {
size+=current_file.length();
}
else {
size+=getDirSize(current_file);
}
}

return size;
}



Replies:
  • Thanx saddysan June 20, 2001 at 2:44 PM (0)

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us