in reply to Restrict file search within current filessystem using wanted subroutine
Simplest way - return if in a directory tree you don't want.
use File::Find; File::Find::find( { wanted => sub { return unless -f; return if ($File::Find::dir =~ /^\/var\/log/); my $s = -s _; return if $min < $s && @z > 10; push @z, [ $File::Find::name, $s ]; @z = sort { $b->[1] <=> $a->[1] } @z; pop @z if @z > 10; $min = $z[-1]->[1]; } }, shift || '.' ); for (@z) { print $_->[0], " ", $_->[1], "\n"; }
Update: a preprocess subroutine seems to be the canonical way to exclude files or directories. But see this post for a caveat I learned about the hard way.
|
|---|