Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Getting size of directory on NT

Posted on 2000-04-24
5
184 Views
Last Modified: 2010-03-05
Hello,

I'm running perl on Win NT.  I'm trying to find a way to get the size of a directory.  I know how to find the size of individual files and I could easily do that and then just add them up.  But the directories have directories within them and so on which would make things difficult.  Is there a way to just get the size of a directory?  If not is their another way to get what I want easily?

Thanks,

Joe
0
Comment
Question by:jvieira
  • 3
  • 2
5 Comments
 
LVL 16

Expert Comment

by:maneshr
ID: 2744247
what do mean by the "size of the directory"??

do you mean the total size of all files under that directory and all the sub directories recursively??

0
 

Author Comment

by:jvieira
ID: 2744379
Yes,

The total size of all files under that directory and all sub directories.

0
 
LVL 16

Accepted Solution

by:
maneshr earned 50 total points
ID: 2744957
try this...

this definately works under UN*X, but i have not tested it under Win*

you can remove the various print statements that i have put.

===========recurse.pl
#!/usr/bin/perl

$DEBUG=0;

foreach $dir (@ARGV){
  push @dir,$dir;
 
  while ($dirs=pop @dir){
    $whereami=`pwd`;
    chomp($whereami);
    chomp($dirs);
    chdir $dirs;
    print "CHANGING to $dirs\n";
     
    while (<*>) {
      next if ($_ eq ".");
      next if ($_ eq "..");
      if (-d $_) {
        next if (-l $_);
        print "\t Dir-> ",$_,"\n" if $DEBUG;
        push @dir,$dirs."/".$_;
      } else {
        ($size) = (stat($_))[7];
        print "\t File-> ",$_," => $size\n" if $DEBUG;
        print "\t",$_," => $size\n" if !$DEBUG;
        $total_size+=$size;
     }
    }
    exit if $DEBUG;
    chdir $whereami;
  }
}

print "Total size = $total_size\n";
0
 

Author Comment

by:jvieira
ID: 2747676

Just change this line:
$whereami=`pwd`;
To:
$whereami=`chdir`;

And it works on WinNT.

Thanks,

Joe
 
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2747870
Cooollll!!

:-)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question