Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: find the latest created file in a directory

by Krambambuli (Curate)
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";


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1030418]
[Corion]: erix: Naah, I just saw the announcement and remembered that discussion. Maybe I'll try building a DBD::SQLite with the zip stuff built-in, just for fun
[Corion]: Oh - and a good morning to you too :)
[erix]: we have these largish series (dozens) of largisch (1-2 GB) tabsep files that might be shrunk a bit in this way. Bound to get a bit slower but that doesn't matter too much for us

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2018-01-24 08:59 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (256 votes). Check out past polls.