Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: find "x" quantity newest files in a dir

by azatoth (Curate)
on Jun 27, 2001 at 13:46 UTC ( #91873=note: print w/replies, xml ) Need Help??

in reply to find "x" quantity newest files in a dir

This does what you're looking for : it's from File Attributes in Win32. All you need to do is change the -A to -M or whatever. Feel free to hack the code as much as you like.

#!perl -w use strict; print "Enter Directory Path : \n"; chomp(my $dirPath = <STDIN>); opendir (DIR, "$dirPath") || die "Fscked Filesystem: $!\n"; my @fileList = grep(!/^\.\.?$/, readdir (DIR)); closedir (DIR); foreach my $file (@fileList) { check_files($file,$dirPath); } ## SUBS ## sub check_files { my $file = shift; my $dirPath = shift; if (-A $file > 30) { print "$file has not been used for over 30 days. De +lete? [y/n]\n"; chomp(my $ans = <STDIN>); if ($ans =~ /^y/) { unlink ("$dirPath\\$file") || die "Could Not + Remove $file : $!\n"; print "Deleting $dirPath\\$file...\n"; } else { print "Skipping File...\n"; } } }
Update: Actually this doesn't do what you're looking for, but the code will help you on your way...

Azatoth a.k.a Captain Whiplash

Make Your Die Messages Full of Wisdom!
Get YOUR PerlMonks Stagename here!
Want to speak like a Londoner?

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2021-01-25 13:22 GMT
Find Nodes?
    Voting Booth?