How can I get the last modified time in a directory in Perl on Windows?

In Perl (on Windows) how to determine the last modified time in a directory?

Note:

opendir my($dirHandle), "$path"; my $modtime = (stat($dirHandle))[9]; 

leads to the following error:

The dirfd function is not implemented in the string line of string.Name.pl.

+4
source share
3 answers

Apparently, the real answer is simply to call stat on the directory path (and not in the directory descriptor, as many examples you might believe) (at least for windows).

Example:

 my $directory = "C:\\windows"; my @stats = stat $directory; my $modifiedTime = $stats[9]; 

if you want to convert it to local time you can do:

 my $modifiedTime = localtime $stats[9]; 

if you want to do all this in one line you can do:

 my $modifiedTime = localtime((stat("C:\\Windows"))[9]); 

On the one hand, the Perl Win32 UTCFileTime module has a syntax error that prevents the perl module from being interpreted / compiled. This means that when it is included in a perl script, the script will also not work properly. When I combine all the actual code that does something in my script and repeat it, Perl eventually runs out of memory and execution stops. In any case, the answer is higher.

+3
source

Use the Win32 :: UTCFileTime CPAN module, which displays the built-in stat function parameter :

 use Win32::UTCFileTime qw(:DEFAULT $ErrStr); @stats = stat $file or die "stat() failed: $ErrStr\n"; 
+3
source
  my $dir_path = "path_of_your_directory"; my $mod_time = ( stat ( $dir_path ) )[9]; 
+2
source

Source: https://habr.com/ru/post/1307197/


All Articles