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

Get file's timestamp in a directory

Status
Not open for further replies.

Newbee21369

Programmer
Oct 13, 2004
30
US
I'm trying to get the timestamp of a file in a directory.
When I run the code shown below I get the following result.
Last change: Time::tm=ARRAY(0x200b6064)
How can I get the this format as my Result?
Last change: 2004111622

#!/usr/bin/perl

use Time::localtime;
$tm = localtime;


opendir(DIR,"/usr/path");
my @dir=grep { !/^\.+$/ } readdir(DIR);
closedir(DIR);
$file_count = 0;

foreach $file (@dir)
{

$mtime = (stat ($file))[9];
print "Last change:\t" . scalar localtime($mtime) . "\n";

}
 
localtime($mtime); #shouldn't need the scalar here to print a date format such as "Sat Jun 35 2004 11:59AM GMT"

@dates=localtime($mtime);
and look at the components from there

months++, year +=1900;

HTH
--Paul

Nancy Griffith - songstress extraordinaire,
and composer of the snipers anthem "From a distance ...
 
Also, you don't need the line use Time::localtime;
perl has a built-in localtime function, but that module overrides it with an object oriented version
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top