Let’s say you have multiple directories that all exist on the same partition. Let’s say you want to find the total bytes used by everything within each directory, whats a good way to do that? Looking at Java File and Apache FileUtils I can only get disk usage information about the partition, but what I need is to be able to limit that down to a specified directory.
Example:
Partition X: 100GB
Root directories:
/x/1/
/x/2/
/x/3/
Deeper directories can exist under each root directory:
/x/1/files/a/deeper/path/test.txt
/x/2/files/test.txt
/x/3/files/path/to/files/test.txt
Goal:
long byteSumForX1 = ??
Say the 3 above paths exist under partition x, i’d like to be able to find the total bytes used by each root directory specified above. The total would need to be recursive and include all files and directories within the root directory
Any ideas? I’d prefer to leverage some existing library for this, if one exists (assuming/hoping it does)
Ths simplest solution would be to use the sizeOfDirectory() method, found in the
FileUtilsclass of Apache Commons. Quoting the javadocs: