in reply to Re: Deleting files
in thread Deleting files

In attempts to suck-up to merlyn, I used File::Finder for the first practical time today, and it totally kicks butt for things like this. The filter-chaining scheme means you can stack filters very cleanly, and it's legal to stick evals in the filter chain as well. So you can filter based on name, time, arbitrary code, etc, and then execute arbitrary code when you are done. It turns File::Find into a quite elegant one liner.

Straight from the docs:

my $blaster = File::Finder->atime("+30")->eval(sub { unlink });
update: be sure you know the difference between atime, mtime, and ctime, as jacques rightfully points out below. mtime is most likely the right one in most scenarios. Chosing the wrong one will mean important things get deleted!