Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Size of File

 
Fisher Daniel
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,
How can I get the size of a folder ?
thanks
daniel
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure if this is exactly what you're looking for, but I was able to come up with the size of all the files within a directory by using a recursive function, like this:

I'm not really sure if there is an easier way to do this or not, but it seems that simply calling the length method on a File object that represents a directory simply returns 0. Therefore, I had to look at each file individually and recurse through any subdirectories. The final result printed the size of all of the files contained within the directory C:\test in bytes.
I hope this helps you out.
Corey
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic