file date

A

Alexandre Jaquet

Hi,

I need to get the files dates on my script. I've found on the web the
following piece of code and explanation :

The -M file check returns the age in days since the file was last
changed. It includes fractional amounts, so if you want to compare days,
you need to take the ‘int’ of the returned value. The -A file check
returns the age in days since someone last looked at the file.

foreach $FileName (@ARGV) {
$FileAge = -M $FileName;
if ($FileAge < .5) {
print "\”$FileName\" is less than half a day old.\n";
} elsif ($FileAge < 1.5) {
print "\"$FileName\" is only a day old.\n";
} else {
$FileAge = int($FileAge+.5);
print "\"$FileName\" is $FileAge days old.\n";
}
}


but I didn't understand what exactly is returned by -M I want to get

"Tue Apr 12 10:11:23"

thanks in advance

Alexandre Jaquet
 
A

Anno Siegel

Alexandre Jaquet said:
Hi,

I need to get the files dates on my script. I've found on the web the
following piece of code and explanation :

The -M file check returns the age in days since the file was last
changed. It includes fractional amounts, so if you want to compare days,
you need to take the ‘int’ of the returned value. The -A file check
returns the age in days since someone last looked at the file.

foreach $FileName (@ARGV) {
$FileAge = -M $FileName;
if ($FileAge < .5) {
print "\”$FileName\" is less than half a day old.\n";
} elsif ($FileAge < 1.5) {
print "\"$FileName\" is only a day old.\n";
} else {
$FileAge = int($FileAge+.5);
print "\"$FileName\" is $FileAge days old.\n";
}
}


but I didn't understand what exactly is returned by -M I want to get

"Tue Apr 12 10:11:23"

The use stat():

my $time = localtime( ( stat $filename)[ 9]);

See perldoc -f stat.

Anno
 
A

Anno Siegel

Alexandre Jaquet said:
Hi,

I need to get the files dates on my script. I've found on the web the
following piece of code and explanation :

The -M file check returns the age in days since the file was last
changed. It includes fractional amounts, so if you want to compare days,
you need to take the ‘int’ of the returned value. The -A file check
returns the age in days since someone last looked at the file.

foreach $FileName (@ARGV) {
$FileAge = -M $FileName;
if ($FileAge < .5) {
print "\”$FileName\" is less than half a day old.\n";
} elsif ($FileAge < 1.5) {
print "\"$FileName\" is only a day old.\n";
} else {
$FileAge = int($FileAge+.5);
print "\"$FileName\" is $FileAge days old.\n";
}
}


but I didn't understand what exactly is returned by -M I want to get

"Tue Apr 12 10:11:23"

Then use stat():

my $time = localtime( ( stat $filename)[ 9]);

See perldoc -f stat.

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,248
Latest member
MagdalenaB

Latest Threads

Top