07/11/2013

Change time properties of file in Windows

Sometime we want to change time properties of file (in Windows). The following Perl script is useful for you:
 $|++;  
 use strict;  
 use warnings;  
 use DateTime::Format::Strptime;  
 use Win32API::File::Time qw{:win};  
 my $parser = DateTime::Format::Strptime->new( pattern => '%m/%d/%Y %H:%M');  
 my $filename="Test.txt";  
 my $cdate="12/10/2012 2:00";  
 my $mdate="12/14/2012 9:00";  
 my ($atime, $mtime, $ctime) = GetFileTime ($filename);  
 $mtime = $parser->parse_datetime($mdate)->epoch;  
 $ctime = $parser->parse_datetime($cdate)->epoch;  
 SetFileTime ($filename, $atime, $mtime, $ctime);  

Bài viết liên quan



Không có nhận xét nào:

Đăng nhận xét