0

I know how to recurse (not re-curse) through a directory structure and get file info etc... e.g. this or that ;)

My question is; is there a more efficient way to do this?

This works well on a 2Gb drive but these days we are using 2Tb and more. I would like to only get the filesize of each file (even the sum of all files in a directory would help). Can one read the OS's disk structure file/data somewhere rather than traversing the whole disk? (Btw, what is the apostrophe rule for abbreviations like OS?)

Thank you.

Community
  • 1
  • 1
TungstenX
  • 830
  • 3
  • 19
  • 40
  • Do you mean you're currently reading in entire files to compute their length? In that case use [`java.io.File.length`](https://docs.oracle.com/javase/6/docs/api/java/io/File.html#length%28%29). – Fred Foo Nov 14 '14 at 11:30
  • No, but I have to scan/list each dir and make a file object for each file in that dir to get the file size. (Not reading the content for the file) – TungstenX Nov 14 '14 at 13:20
  • You could read the raw disk, but you would need to understand the underlying file system format. The problem you have is that a 2 TB disk only spins and its head moves so fast. If you want more IOPS, you need to use SSD which can be 1000x faster at these sort of operations. – Peter Lawrey Nov 16 '14 at 11:49
  • I can remember vaguely (15 years ago) that the OS kept a file of some sorts that contain the directory structure, some file info and where on the physical disk the file is. I assume it is different for each OS but isn't there some common lib for this? – TungstenX Nov 17 '14 at 12:51

0 Answers0