Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: file size help

by arthas (Hermit)
on Jun 17, 2003 at 15:38 UTC ( #266617=note: print w/replies, xml ) Need Help??


in reply to file size help

This should do what you need:

$bytes = (stat('test.jpg'))[7]; $kbytes = int($bytes/1024);

As an alternative, you can use -s insstead of stat():

$bytes = -s 'test.jpg';

Michele.

Replies are listed 'Best First'.
Re: Re: file size help
by rob_au (Abbot) on Jun 17, 2003 at 19:27 UTC
    One note which I would add to this, is that both of these functions employ the stat() function "under the hood" - Information returned from this call is cached such that subsequent calls to stat, lstat or the -X file tests employing the special filehandle consisting of a solitary underline character (_) can employ this cached information rather than again calling the underlying stat() function.

    This behaviour is documented in perlfunc.

     

    perl -le 'print+unpack"N",pack"B32","00000000000000000000001001101011"'

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2019-05-22 06:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (138 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 18:53 UTC) Welcome new users!