Get file modified/accessed time
#!/usr/bin/perl
use strict;
use warnings;
foreach my $file ( @ARGV ) {
print( "Checking $file: " );
if ( -e $file ) {
print( "$file exists!\n" );
if ( -f $file ) {
print( "The file $file is:" );
my @time = timeconv( -A $file );
print( "Last accessed at $time[0] days, ","$time[1] hours, $time[2] minutes ","and $time[3] seconds.\n" );
@time = timeconv( -M $file );
print( "Last modified at $time[0] days, ","$time[1] hours, $time[2] minutes, ","and $time[3] seconds ago.\n" );
}
elsif ( -d $file ) {
print( "$file is a directory!\n" );
}
}
else {
print( "$file doesn't exist.\n" );
}
print( "\n" );
}
sub timeconv
{
my $time = shift();
my $days = int( $time );
$time = ( $time - $days ) * 24;
my $hours = int( $time );
$time = ( $time - $hours ) * 60;
my $minutes = int( $time );
$time = ( $time - $minutes ) * 60;
my $seconds = int( $time );
return ( $days, $hours, $minutes, $seconds );
}
Related examples in the same category