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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

file atttibutes using the "ls -l"

Status
Not open for further replies.

abovebrd

IS-IT--Management
May 9, 2000
690
0
0
US
I am hopeful that someone might be able to give me a pointer. I am listing file atttibutes using the "ls -l" command. I need to alter the mode time ($mtime) into as more usable format. Can someone recomend an approach to this ?

The script I'm using is below.

#!/usr/bin/perl

print "Content-type: text/html\n\n";
print &quot;<h1> Listing </h1>&quot;;

use File::Listing;
for (parse_dir(`ls -l`)) {
($name, $type, $size, $mtime, $mode) = @$_;
@log = qw($name $type $size $mtime $mode);
print &quot;<LI><a href=\&quot;$name\&quot;>$name $mtime $type</a>\n\n&quot; unless
($name =~ /^\.+$|index|htaccess|test/);
}


-Danny
dan@snoboarder.net






 
look up the stat function, and have a time function that'll give you the format you want ... what format do you want?

HTH
Paul



It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Paul,

I'll check out the stat function. thanks.

What I want to do is output $mtime into a more reader friendly output.

the script does this for $mtime 1054750200

this is what I want : Jun 4 11:10

or something close to it.

cheers

-Danny
dan@snoboarder.net






 
localtime() function was the key

$modtime = localtime($mtime);

Complete script below:

#!/usr/bin/perl

print &quot;Content-type: text/html\n\n&quot;;
print &quot;<h1>Statistics </h1>&quot;;
use File::Listing;
for (parse_dir(`ls -l`)) {
($name, $type, $size, $mtime, $mode) = @$_;
@log = qw($name $type $size $mtime $mode);
$modtime = localtime($mtime);
print &quot;<LI><a href=\&quot;$name\&quot;>$name :Modified time: $modtime</a>\n&quot; unless
($name =~ /^\.+$|index|htaccess|test/);
}


-Danny
dan@snoboarder.net






 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top