Solved

Getting size of directory on NT

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

21 Experts available now in Live!

Get 1:1 Help Now