Real Perl has asked for the wisdom of the Perl Monks concerning the following question:
Beloved,
When I write:and I give it a directory that has MB or GB of data, the numbers that are coming back are not correct. Basically, I need to call a size method on some directory and collect that number and if necessary change it to be in MB. I will also need to do that with a list of directory.#!/usr/bin/perl -w use strict; use Tk; use File::stat; my $mw;#first window my $logl; #label for log my $logtf; #entry box for the log name my $path=""; #hol my $total=0; $mw = MainWindow -> new(); $logl = $mw ->Label (-text=> '\path', -font=>"Adobe 10")->pack; $logtf = $mw ->Entry (-textvariable=> \$path, width=>25)->pack; my $okb =>$mw -> Button(-text=>'GO', -command => sub {size()})->pack(- +side =>'right'); MainLoop; sub size{ chdir $path; opendir DIR, $path; my @file = readdir DIR; closedir DIR; foreach my $file (@file) {$st = stat($file) or die "No $file: $!"; $total = ($st->size)/1048576;#converts from bytes to MB }#foreach print "$total MB for this directory or file"; }#size
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Finding the size of a directory
by osunderdog (Deacon) on Aug 06, 2005 at 00:12 UTC | |
|
Re: Finding the size of a directory
by davidrw (Prior) on Aug 06, 2005 at 00:16 UTC | |
|
Re: Finding the size of a directory
by chester (Hermit) on Aug 06, 2005 at 02:11 UTC | |
by Real Perl (Beadle) on Aug 06, 2005 at 18:34 UTC |