Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Finding Last minute file in a directory

by zwon (Abbot)
on Aug 16, 2009 at 16:23 UTC ( [id://789031]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://789031]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-04-25 15:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found