CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Filesize

 



scuffed
stranger

May 8, 2001, 10:56 AM

Post #1 of 3 (494 views)
Filesize Can't Post

ok i am trying to show the filesize on something i am making i ripped this script off of fileman which shows the file sizes
sub fs {
# --------------------------------------------------------
# Prints out the file size.

my $size = shift;
my $formatted_size = int($size / 1024) . " kb";
$formatted_size == 0 ?
return "$size bytes" :
return $formatted_size;
}
and i made all the variables along with the filesize and crap but it still wouldn't show the file size of the file i needed. can anyone help me out with this please?



rjoseph
Novice

May 8, 2001, 12:46 PM

Post #2 of 3 (491 views)
Re: Filesize [In reply to] Can't Post

It seems that something is broken in the way you get the size of the file in the first place (atleast everything else seems like it would work). The -s modifier will return the size of a file, or you could use the stat(). Here is how I would do it though:

Code
my $size = -s 'my_file.txt'; 
my $kb_s = int($size / 1024);

Of course, I would use sprintf to round because you can specify decimal places to round to, and it is more accurate.

Hope that helps!

r j o s e p h
"Violence is a last resort of the incompetent" - Foundation


scuffed
stranger

May 8, 2001, 9:09 PM

Post #3 of 3 (484 views)
Re: Filesize [In reply to] Can't Post

Well thank you i am basically new at this stuff right now and i appreaciate it thank you.


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives