Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Disk Space used by a folder (and sub folders)

by dws (Chancellor)
on Jan 25, 2001 at 22:20 UTC ( #54313=note: print w/replies, xml ) Need Help??


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.

  • Comment on Re: Disk Space used by a folder (and sub folders)

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://54313]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2021-04-20 07:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?