in reply to Finding Last minute file in a directory
This code will find the file modified less than a minute ago:
use strict; use warnings; use 5.010; use File::Spec; my $dirname = '.'; opendir( my $dir, $dirname ) or die $!; my $file; while ( $file = readdir($dir) ) { last if ( stat( File::Spec->catfile( $dirname, $file ) ) )[9] + 60 + > time; $file = ''; } say $file;
Alternatively (it depends on what you really need if that solution would fit you), if there's only log files in directory, you can get list of files, sort it, and use last file.
|
|---|