weissman
asked on
directory and files listing in perl
hi All,
i am tring to build a html page that display a directory listing using perl script...
first i have to use perl so i have use:
my @files = glob("*");
to get all the files and display it in the page the problem that i need to display also
the file last modify and size!
i have use stat($file) but it disn'y display the length of files!
here is the code i have write:
my @files = glob("*");
$filesLink="";
foreach $file (@files) {
@ABC = (stat($file));
$filesLink = $filesLink."<tr><td valign=\"top\"></td><td><A href=\"maintenance/"."$fil e"."\">"." $file"."</ A></td><td align=\"right\">---------- -$ABC['Fil e::stat'][ 9] ------------------------ </td><td align=\"right\">763K</td>< td> < /td></tr>" ;
}
i have also try to use this asample from the internet also it didn't work:
my $path = "maintenance/";
$opendir my $ls,$path or die $!;
while (my $file = readdir $ls ) {
next if !-f "$path/$file";
my @stat = stat("$path/$file");
push @files, [ $file , localtime($stat[9]) ];
}
closedir $ls;
please help
thanks a lot
i am tring to build a html page that display a directory listing using perl script...
first i have to use perl so i have use:
my @files = glob("*");
to get all the files and display it in the page the problem that i need to display also
the file last modify and size!
i have use stat($file) but it disn'y display the length of files!
here is the code i have write:
my @files = glob("*");
$filesLink="";
foreach $file (@files) {
@ABC = (stat($file));
$filesLink = $filesLink."<tr><td valign=\"top\"></td><td><A
}
i have also try to use this asample from the internet also it didn't work:
my $path = "maintenance/";
$opendir my $ls,$path or die $!;
while (my $file = readdir $ls ) {
next if !-f "$path/$file";
my @stat = stat("$path/$file");
push @files, [ $file , localtime($stat[9]) ];
}
closedir $ls;
please help
thanks a lot
ASKER
hi ozo,
thank you for quick respond ... i have use $ABC['File::stat'][7] but didn't work either
what do you mean by :
Argument "File::stat" isn't numeric in array element
sorry i am new to perl but i know java
should i use glob or readdir
thanks.
thank you for quick respond ... i have use $ABC['File::stat'][7] but didn't work either
what do you mean by :
Argument "File::stat" isn't numeric in array element
sorry i am new to perl but i know java
should i use glob or readdir
thanks.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks ozo,
although i didn't know what is the difference between $ABC[7] and @ABC[7] they display the
same result : (4096)
test 1386676710 4096
can i ask you how to format the 4096 to be displayed in kb/mb instead
and how to displat last modify in date format ex. 10-Dec-2013 11:58
thanks a lot
although i didn't know what is the difference between $ABC[7] and @ABC[7] they display the
same result : (4096)
test 1386676710 4096
can i ask you how to format the 4096 to be displayed in kb/mb instead
and how to displat last modify in date format ex. 10-Dec-2013 11:58
thanks a lot
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks a lot to you ozo, Dave
i have managed to display the date in format using :
$datestring = localtime($ABC[9]);
although it is not my fevorite format but it is okay now
my last question how to format the bytes in MB /KB i need a function that check the size and if it bigger than 1024 kb then display it in MB instead of kb ...
thanks a lot
i have managed to display the date in format using :
$datestring = localtime($ABC[9]);
although it is not my fevorite format but it is okay now
my last question how to format the bytes in MB /KB i need a function that check the size and if it bigger than 1024 kb then display it in MB instead of kb ...
thanks a lot
You can customize the date format with POSIX::strftime
ASKER
Thanks
" $ABC['File::stat'][9] " should give you the warning
Argument "File::stat" isn't numeric in array element
There should not be a $ in $opendir