Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Delete all but the most recent backup file

by kielstirling (Scribe)
on Jan 24, 2013 at 04:44 UTC ( #1015073=note: print w/ replies, xml ) Need Help??


in reply to Delete all but the most recent backup file

Hey, Not sure if I understand the question ... but, this will give you the last modified file.

#!/usr/bin/perl use Modern::Perl; use IO::Dir; my $path = shift; my $dir = IO::Dir->new($path); my %files; for my $file (grep !/^\./, $dir->read) { $files{$file} = (stat("$path/$file"))[9]; } my $file = (sort {$files{$a} <=> $files{$b}} keys %files)[0]; say "$file ", scalar localtime($files{$file}); undef $dir;


Comment on Re: Delete all but the most recent backup file
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2015-07-06 23:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (85 votes), past polls