Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: find the latest created file in a directory

by Krambambuli (Curate)
on Apr 24, 2013 at 14:17 UTC ( [id://1030418]=note: print w/replies, xml ) Need Help??


in reply to find the latest created file in a directory

Maybe this comes close to what you want:
#!/usr/bin/perl use strict; use warnings; use File::stat; my $DIR = './'; opendir(my $DH, $DIR) or die "Error opening $DIR: $!"; my @files = map { [ stat "$DIR/$_", $_ ] } grep( ! /^\.\.?$/, readdir( $DH ) ); closedir($DH); sub rev_by_date { $b->[0]->ctime <=> $a->[0]->ctime } my @sorted_files = sort rev_by_date @files; my @newest = @{$sorted_files[0]}; my $name = pop(@newest); print "Name: $name\n";

Krambambuli

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (1)
As of 2024-04-25 00:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found