Gossamer Forum
Home : General : Perl Programming :

file size

Quote Reply
file size
This code will get the file name(s), and print them to the screen:

Code:
opendir(DIR, ".");
@htmlFiles = grep(/\.html$/,readdir(DIR));
closedir(DIR);
foreach $file (@htmlFiles)
{
print "$file<BR>\n";
}

Does anybody knows how to get the size of the file?

Thank you,

Pasha

------------------
webmaster@find.virtualave.net
http://find.virtualave.net
Quote Reply
Re: file size In reply to
Try:

Quote:
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($filename);

The size of the file will be in... you guessed it... $size. Smile

You would probably have to change your code to assign $filename the name of the file.

I hope this helps.
Quote Reply
Re: file size In reply to
There's always more then one way to do it:

$size = -s '/path/to/file.txt';

will return the size of the file.

Cheers,

Alex
Quote Reply
Re: file size In reply to
I would like to know other info about a file such as last time it was updated or the first time it was uploaded.

And Bobsie said:
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)
= stat($filename);
So I am guessing either:
$atime, $mtime, or $ctime is the time that the file was last updated or first uploaded.
If you can , please let us know what exactly does each of the varibles represent?

Also, Alex, is there any "other way" to get the time (updated/uploaded) of a file?

Thank you very much for your time (reading this/answering this) Wink !
Quote Reply
Re: file size In reply to
Sure:

$days_old = -M '/path/to/file';

will return the number of days since last modified.

Other then that, see 'perldoc -f stat' for info on the stat function.

Cheers,

Alex
Quote Reply
Re: file size In reply to
   Is there a way to know the size of a file in other server?
I mean, if the user enters a file location, i.e. http://www.yahoo.com/ban.gif
I would like to know what is this file size!
Is it possible?
Quote Reply
Re: file size In reply to
Sure:

use LWP::Simple;
$file = get ('http://www.yahoo.com/ban.gif');
$size = length ($file);

Cheers,

Alex