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.

But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

  • Comment on Re: Restrict file search within current filessystem using wanted subroutine
  • Download Code