Get timestamp using perl script

I am new to perl scripting,  i need a a perl script to copy a directory from remote machine to my local machine and print the filenames and its timestamp in the directory and its subdirectories which is been copied to local machine.  this perl script  should work both in unix and windows.
frnxxAsked:
Who is Participating?
 
fsouzabrasilCommented:
This perl print timestamp, use this code to you.
#!/usr/bin/perl -w
#
@Month_name = ( "January", "February", "March", "April", "May", "June",
  "July", "August", "September", "October", "November", "December" );
( $sec, $min, $hour, $day, $month, $year ) = ( localtime ) [ 0, 1, 2, 3, 4, 5 ];
printf  "%02d:%02d:%02d %02d %s %04d\n",
  $hour, $min, $sec, $day, @Month_name->[$month], $year+1900 ;
exit;
0
 
FishMongerCommented:
Do you want the current timestamp or the mtime or ctime of the file?

If you need the file's timestamp, then look at the stat function.
http://perldoc.perl.org/functions/stat.html


Here's a clean way to output a formatted timestamp.

#!/usr/bin/perl

use strict;
use warnings
use POSIX;

print strftime('%H:%M:%S %d %B %Y', localtime);

Open in new window

0
 
vikaskhoriaCommented:
To get the timestamp of a file in $file use the following code:



use File::stat;
use Time::localtime;

$date_string = ctime(stat($file)->mtime);
print "Timestamp of file $file: $date_string\n";

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.