How to find folder size in java without using recursive traversal?

I am developing a small application for creating and maintaining monthly backups. Here I want to get the size of the folder to check if there is enough free space on the target disk or not. I move the directory structure once to take a backup (copy the same dir structure.) Now, to find the size, as I mentioned, I don't want to use recursion. Is there any other simpler method?


Thanks to all of you, I finally used org.apache.commons.io.FileUtils to complete the task after all this package also uses recursion.

+4
source share
4 answers

Not sure if this is possible.

Even FileUtils.sizeOfDirectory () in apache-commons IO uses recursion to get the size of the directory.

+4
source

I believe this is not possible. Even operating systems must recursively go through directory structures to determine the size of the directory. As far as I know, no modern file system stores the size of all contained files.

+1
source

Java functionality like this is implemented as part of the Java API. Nothing provides what you want. Apache Commons offers the FileUtils library, which has sizeOfDirectory . Recursion is certainly used in this. Why don't you want to use recursion?

0
source

Why do not you determine the size of the directory during the first recursive pass?

0
source

All Articles