in reply to Finding the size of a directory

Is there any possibility the directory contains subdirectories? readdir will find those, but no files in them. readdir also finds '.' and '..', which it doesn't seem you take into account. stat returns true for directories, and it returns a filesize for directories which you may or may not want.

If you want to recurse and only pick up files, perhaps this is a job for File::Find and friends, rather than readdir. There's also Win32::DirSize if you're on Windows.

Replies are listed 'Best First'.
Re^2: Finding the size of a directory
by Real Perl (Beadle) on Aug 06, 2005 at 18:34 UTC

    Hi,

    My program has two different modes. When the user in on the first mode, he can only enter one path (c:\mydirectory\file.txt or c:\directory). My job is to make perl get the size of what was entered.
    When the user is on the second mode, he not only gives me the path (c:\directory\), but in a textarea, I make him give me a bunch of directories which I will append to c:\directory\ so what I give Perl looks like c:\directory\thedirectoryfromtextarea. What is in the textarea can be files or directories.
    What do you recommand I use to get the size that would cover both modes?
    As a side note, I tried installing Win32::DirSize and it is telling me it cannot found it but I need to do a "broader search" and when I type search Win32::DirSize it says there is no match for Win32::DirSize. I tried downloading it from activeperl, but it is not available either. I don't know what to do!
    Thanks in advance for your help,
    Claire