Solved

Getting size of directory on NT

Posted on 2000-04-24
5
170 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to tell if a file is being written with Perl running on a Windows 2003 Server 12 35
PERL get the value for query 4 145
create a gui in perl 3 72
Perl tar error 8 51
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now