Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: How do I recursively count file sizes in a script that works under both Windows and Linux?

by Crulx (Monk)
on Jan 22, 2000 at 01:28 UTC ( #2317=note: print w/replies, xml ) Need Help??


in reply to How do I recursively count file sizes in a script that works under both Windows and Linux?

Here is a cross-platform way of doing it.
use strict; my $dir = '.'; print &dir_tree_size($dir) . "\n"; exit 0; sub dir_tree_size { my $dir = shift; my ($i,$total); $total = 0; opendir DIR, $dir; my @files = grep !/^\.\.?$/, readdir DIR; for $i (@files) { if(-d $i) { $total += dir_tree_size($dir . "/$i") } else { $total += -s $i} } return $total; }
Crulx
  • Comment on Re: How do I recursively count file sizes in a script that works under both Windows and Linux?
  • Download Code

Replies are listed 'Best First'.
Re: Answer: How do I recursively count file sizes in a script that works under both Windows and Linux?
by Anonymous Monk on Sep 12, 2001 at 12:34 UTC
    This always return 5333 on SuSE Linux 7.2 Kernel 2.4.4 Mark
RE: Answer: How do I recursively count file sizes in a script that works under both Windows and Linux?
by Anonymous Monk on Aug 31, 2000 at 22:09 UTC
    This doesnt seem to work recursively, just counts files in the current directory, not the subdirs.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2022-09-27 03:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer my indexes to start at:




    Results (118 votes). Check out past polls.

    Notices?