Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting A Directory Or File Size

 
Jonathan Fleming
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to you get a directory or file size into an instance variable?
Thanks
Jonathan :^)
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the java.io.File class. You can create an instance with a filename arg and then check the length. I don't know what it will do for a directory.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On my Windows XP machine, the length of a directory is 0.
To get the total size of all files in a directory, take a look at that File.listFiles() method.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rats, you may have to use recursion to the ends of the tree to get the size of all files in a directory. I do this in REXX and make a CSV with these columns:
directory
#files in this directory
#bytes in those files
#files in this plus all subdirectories
#bytes in those files
It's an interesting way to explore disk usage. There are a number of fascinating ways to graph this kinda thing. There is much fun to be had if you want to follow it up.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic