Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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?


Comment on Re: find "x" quantity newest files in a dir
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2014-12-18 04:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (41 votes), past polls