Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Question:

I need to find the largest (space usage wise) directory on a drive. The drive is on a windows 2000 machine.

What is the easiest way to do this.

i've tried the following (please forgive incomplete code, i didn't feel it was needed here):
$size = -s "$dirname"; #this returns 0 opendir(DIR, $dirname); $size = -s readdir(DIR); #again 0 ( .... ) = stat(DIR); #returns a filename to $size

The only think i can come up with is a routine to recursively get the size of each file, and recurse on any directories it finds. This however is boring :)

Any ideas?

Replies are listed 'Best First'.
Re: Directory Size
by Beatnik (Parson) on Jul 26, 2001 at 22:08 UTC
Re: Directory Size
by bikeNomad (Priest) on Jul 26, 2001 at 22:09 UTC
    Take a look at this thread. How else would you define the "size of a directory" rather than as the sum of its files' sizes? Remember to round up to filesystem block boundaries on file sizes, and to count the sizes for the directory entries themselves (usually only a few blocks at most).
Re: Directory Size
by LD2 (Curate) on Jul 26, 2001 at 22:23 UTC
Re: Directory Size
by John M. Dlugosz (Monsignor) on Jul 26, 2001 at 23:34 UTC
    Under Win2k you say? Using the 4NT shell, I'd grep dir /su for "\s+Total for:". There may be similar flags on the included CMD.EXE.