Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

How can I determine the size of a file?

by Anonymous Monk
on Sep 25, 2000 at 19:46 UTC ( #33916=perlquestion: print w/replies, xml ) Need Help??

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";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://33916]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2021-04-21 05:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?