Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: find the latest created file in a directory

by Krambambuli (Deacon)
on Apr 24, 2013 at 14:17 UTC ( #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


Comment on Re: find the latest created file in a directory
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2014-08-28 12:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (259 votes), past polls