Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
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 ( [id://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?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-16 17:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found