Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Obtaining a files size on win32

Status
Not open for further replies.

jimmyJIMMYyaya

Programmer
Sep 30, 2001
13
CA
Hey all

Im trying to get a files size but here the prob im having

i have a foreach loop like so which i was hoping would return a files size but no go.

foreach $file (@array)
{
@stat = (stat($file))[7];
}


how can i get a files size on win32

thanks for anyones help in advance
jimmyJIMMYyaya

 
If the the file size is all you want
then your code can be modified as below

foreach $file (@array)
{
if ( -f $file )
{
$filesize=(stat($file))[7];
}
}


HTH

[

Although your code is syntactically correct,
the (stat($file))[7] returns a scalar which is being assigned to a list.If you need some other data reg the file you might want to try

(stat($file))[7,8] # Size and access time of file
which returns a list.

]


C
 
ok this still isn't working?

what im doing is reading a directory into @dirData
then i perform a foreach loop assigning each item to $file.

so in my foreach loop i just added

if ( -f $file )
{
$fileSize = (stat($file))[7];
}

and then i try printing $fileSize in my html response but nothing is in the variable?
what the heck am i doing wrong here. do i need a path to the file for the check to work correctly cause right now its just the filename this is the only thing else that i can think of?
 
This works perfectly for me .

#=================================
# filesize
#=================================

#!/usr/bin/perl

opendir(THIS,".") or die "File Open Error";
@files=grep !/^\.\.*?/,readdir THIS;
close(THIS);

print "Content-Type: text/html\n\n";
foreach $file (@files)
{
if(-f $file )
{
$size=(stat($file))[7];
}

print &quot;<b>$file</b> - $size <br>\n&quot;;


}


#=======================================

Posting your actual code might help


regards
C

&quot;Brahmaiva satyam&quot;
-Adi Shankara (788-820 AD)
 
hey all i figured out my filesize problem


when i opened the directory for reading i never changed into the directory first so it was assigning 0 to every filesize. So when i used the chdir( &quot;dir&quot; ); command it finally returned the filesize thanks for all of your help :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top