in reply to Re^2: How do I traverse the files in descending order of modification using File::Find
in thread How do I traverse the files in descending order of modification using File::Find
If you want to avoid modifying existing code too much, you could try something like
use File::Find; my @files; find(\&collect, "."); sub collect { # 'wanted' function replacement push @files, [ $File::Find::name, (stat)[9] # mtime ]; } sub wanted { # your original 'wanted' function # ... } my @files_by_age = sort { $a->[1] <=> $b->[1] } @files; for my $entry (@files_by_age) { my $fullname = $entry->[0]; my ($dir, $name) = $fullname =~ /(.*?)([^\/]*)$/; # set variables that File::Find would have set $File::Find::name = $fullname; $File::Find::dir = $dir; $_ = $name; # depending on whether you need it, you might want to # chdir() into the directory # ("left as an exercise ..." :) # call wanted() function as File::Find would have done wanted(); }
(Depending on exactly how you're using File::Find, you might need to finetune the approach... this is just an outline of basic usage.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: How do I traverse the files in descending order of modification using File::Find
by pravlm (Acolyte) on Apr 06, 2009 at 20:56 UTC |