in reply to perl - File::Find::Rule to exclude a single dir
am trying to get the list of latest files in each dir(for each project) under a specific path ($output) , excluding a single dir OLD How can I frame a rule to achieve this?
file find rule date, file find rule date, file find rule date, site:perlmonks.org file find rule date
untested
#!/usr/bin/perl -- use strict; use warnings; use File::Find::Rule qw/ find rule /; Main( @ARGV ); exit( 0 ); sub Main { my @dirs = ProjectDirsInExcept( $output, 'OLD' ); for my $dir (@dirs) { my ($file) = LatestFile($dir); print "$file\n"; } } sub ProjectDirsInExcept { my ( $in, @except ) = @_; my @dirs = find( directory => not_name => \@except, maxdepth => 1, in => $output, ); return @dirs; } sub LatestFile { my ($dir) = @_; my @files = find( file => maxdepth => 2, in => $dir ); @files = map { $$_[0] } sort { $$b[1] <=> $$a[1] } map { [ $_, ( stat $_ )[9] ] } @files; return shift @files; } __END__
|
|---|