Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how do I get size folders ?  RSS feed

 
nhu dinh thuan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
help me , please !
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

As far as I can see from the java.io API, you would have to create a new File() for the folder. Then sum File.length() for each file returned by File.listFiles() recursively for each sub-folder. I guess this would only give an estimate of the actual folder size.

A platform-dependent alternative that might give a more accurate figure would be to use Runtime.getRuntime().exec() to submit an appropriate command to the underlying OS. That's not as straightforward as it sounds.

Jules
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!