Using this code.D:\ENV>perl pm10.pl Holli (New). Found: 1 ( D:\env\Videos/2012 ) Time: -19 Holli (original). Found: 1 ( d:\env/Videos/2012 ) Time: -32 ovedpo15. Found: 1 ( d:/env/Videos/2012 ) Time: -51
use File::Find; use File::Spec::Functions; use Cwd qw(abs_path); sub holli2 { my @found; my $path = 'd:\env'; my $target = "2012.avi"; myfind( \@found, $path, $target ); print "Holli (New). Found: ", scalar @found, " ( @found )", "\n"; } sub myfind { my ($found, $path, $target ) = @_; if ( opendir( my $in, $path ) ) { while ( my $dir = readdir($in) ) { next if $dir =~ /^\.\.?$/; my $entry = "$path/$dir"; if ( -d $entry ) { myfind( $found, $entry, $target ) } else { push @$found, $path if ($dir eq $target) && (!-e "$path/.ignore"); } } closedir($in); } else { print qq(Skipping "$path": $!\n); return; } } sub holli { my @found; my $path = 'd:\env'; my $target = "2012.avi"; find ( sub { # We're only interested in directories return unless -d $_; # Bail if there is an .ignore in the current directory return if -e "$_/.ignore"; # Add to the results if the target is found here push @found, $File::Find::name if -e "$_/$target"; }, $path); print "Holli (original). Found: ", scalar @found, " ( @found )", " +\n"; } sub ovedpo15 { my @found; find( sub { get_dirs( \@found, $_ ) }, 'd:\env'); print "ovedpo15. Found: ", scalar @found, " ( @found )", "\n"; } sub get_dirs { my ($dirs_aref, $current_path) = @_; $triesOvedpo15++; eval { my $abs_path = abs_path($current_path); my $file = $abs_path."/2012.avi"; my $ignore_file = $abs_path."/".".ignore"; push (@{$dirs_aref},$abs_path) if((-e $file) && !(-e $ignore_f +ile)); }; } my $t = time(); holli2(); print "Time: ", ($t - time), "\n"; $t = time(); holli(); print "Time: ", ($t - time), "\n"; $t = time(); ovedpo15(); print "Time: ", ($t - time), "\n";
In reply to Re^5: Finding files recursively
by holli
in thread Finding files recursively
by ovedpo15
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |