Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Getting size of directory on NT

Posted on 2000-04-24
5
Medium Priority
?
205 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
[X]
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
  • 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 200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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 …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
Six Sigma Control Plans

730 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