http://qs1969.pair.com?node_id=54313


in reply to Disk Space used by a folder (and sub folders)

That will give you the total size of files, but not the total space used on the filesystem for the files. If you care about that distinction, you'll need to determine what the BLOCKSIZE is on the filesystem that the files reside on, and round each file's size up to the nearest multiple of that blocksize before summing.

As for determining blocksize.. that varies with OS. It's often 512 bytes, but can be quite a bit larger depending on how the filesystem is configured.

Replies are listed 'Best First'.
Re: Re: Disk Space used by a folder (and sub folders)
by $code or die (Deacon) on Jan 25, 2001 at 23:52 UTC
    That's a very good point! Thanks. I mainly use Win32, and I think that there are a few Win32 modules that will return the block size.

    $code or die
    Using perl at
    The Spiders Web
      hm, doesn't stat function exist on win32? :))
      #!/usr/bin/perl -w use strict; use File::Find; print "Total: ", GetFolderSize( defined $ARGV[0]?$ARGV[0]:'.'), $/; sub GetFolderSize { local $% = 0; find( { wanted => sub { local ($-,$=) = (-s,(stat)[11]); $%+=(int($-/$=)+($-%$=?1:0))*$= }},shift);$% }

      --
      AltBlue.

        Not sure, but I got an illegal divide by zero error when running your example.

        I'll play around with your code and see if I can get it to work.

        $code or die
        Using perl at
        The Spiders Web