Solved

Getting size of directory on NT

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

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 …
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…
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…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

813 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

19 Experts available now in Live!

Get 1:1 Help Now