http://www.perlmonks.org?node_id=33916

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question: (files)

How can I determine the size of a file on my apache server with perl?

Originally posted as a Categorized Question.

  • Comment on How can I determine the size of a file?

Replies are listed 'Best First'.
Re: How can I determine the size of a file?
by fundflow (Chaplain) on Sep 25, 2000 at 20:18 UTC
Re: How can I determine the size of a file?
by BastardOperator (Monk) on Sep 25, 2000 at 19:55 UTC
    I'm guessing that you wanted to do this from a cgi, right?

    Assuming that the file is:
    A) within the chroot jail made by Apache
    B) readable by the user

    you can do something like
    my $file = "some/file"; # relative path within chroot my $fsize = (stat($file))[7]; # in bytes
    <!- Added CODE tags, changed title (turnstep) -->
Re: How can I determine the size of a file?
by phenom (Chaplain) on Jun 23, 2004 at 00:46 UTC
    Although it's the same difference, if you want to use a module, try File::stat.
    #!/usr/bin/perl use strict; use warnings; use File::stat; my $file = shift; my $st = stat($file); my $size = $st->size; print $size, "KB";