Getting File Size 
Author Message
 Getting File Size

Quote:

>The UNIX command is 'du + filename'.  However, I'm not one to want to make
>a lot of system specific calls.  Is there a manner in Perl to echo back a
>given file's size?

Check out the file test operators in the documentation (perlfunc)

  $file = '/boot/vmlinuz';
  if (-f $file) {
    $size = -s _;
    print "$file is $size bytes\n";
  }

Hope this helps,

Mike

--

http://www.*-*-*.com/ ~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.*-*-*.com/ ;  |                   65 F3 3F 1D 27 22 B7 41



Fri, 05 Nov 1999 03:00:00 GMT  
 Getting File Size

Quote:

>The UNIX command is 'du + filename'.  However, I'm not one to want to make
>a lot of system specific calls.  Is there a manner in Perl to echo back a
>given file's size?

>Thanks!

>Chuck Wyatt

   Check out the stat() function.  It returns an array of all kinds of
info on a given file, one of which is file size.  Try something like

  $size = (stat("filename"))[7];  # Grab 8th element of list returned by stat

                                                Bill
--
Sending me unsolicited email through mass emailing about a product or
service your company sells ensures that I will never buy or recommend your
product or service.



Fri, 05 Nov 1999 03:00:00 GMT  
 Getting File Size



++ The UNIX command is 'du + filename'.  However, I'm not one to want to make
++ a lot of system specific calls.  Is there a manner in Perl to echo back a
++ given file's size?

perl -we '$_ = shift; printf "%6d %s\n", -M, $_' file

That doesn't simulate du's behaviour for directories though.

Abigail



Fri, 05 Nov 1999 03:00:00 GMT  
 Getting File Size

Quote:



> ++ The UNIX command is 'du + filename'.  However, I'm not one to want to make
> ++ a lot of system specific calls.  Is there a manner in Perl to echo back a
> ++ given file's size?

> perl -we '$_ = shift; printf "%6d %s\n", -M, $_' file

> That doesn't simulate du's behaviour for directories though.

> Abigail

Abigail,

This is an interesting trick.  How did you discover it?

Anyway, the original question asked for a techinque
to get file sizes; the '-M' would have to be changed
to '-s' to accomplish this...

E.g, the following script returns the size and name of any
file given as an argument when run:

  #!/bin/perl

  $_ = shift;

  printf "%6d %s\n", -s, $_;

--
"If the universe is expanding, why can't I find a parking space?..."

     David S. Patterson, Sr. Software Engineer
     Production Illustration Systems  (206) 865-3176



Sun, 07 Nov 1999 03:00:00 GMT  
 Getting File Size

On Wed, 21 May 1997 18:56:17 GMT, David S. Patterson

<URL: :">
++ >


++ > ++ The UNIX command is 'du + filename'.  However, I'm not one to want
++ > ++ to make
++ > ++ a lot of system specific calls.  Is there a manner in Perl to echo
++ > ++ back a
++ > ++ given file's size?
++ >
++ > perl -we '$_ = shift; printf "%6d %s\n", -M, $_' file
++ >
++ > That doesn't simulate du's behaviour for directories though.
++ >
++ > Abigail
++
++ Abigail,
++
++ This is an interesting trick.  How did you discover it?

By reading the manual pages, and the blue Camel.

++ Anyway, the original question asked for a techinque
++ to get file sizes; the '-M' would have to be changed
++ to '-s' to accomplish this...

Indeed. Silly me.

Abigail



Mon, 08 Nov 1999 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. problem getting file size in forked code

2. CGI.pm Bug: file upload file size mismatch when file size is close to buffer size

3. Getting Remote File Size

4. HELP! Getting Remote File Size

5. (Q) getting a file's size in Perl

6. getting remote file sizes

7. getting a file size

8. Differences in the file size reported by Net::FTP->size and ls -l

9. Getting Traffic Size in Bytes from W3C Extended Format Log

10. Getting partition size from perl script

11. Getting NTFS Directory structure size

12. getting object size?

 

 
Powered by phpBB® Forum Software