in reply to Re^4: Finding files recursively
in thread Finding files recursively
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";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Finding files recursively
by ovedpo15 (Pilgrim) on Aug 05, 2019 at 17:53 UTC | |
by holli (Abbot) on Aug 05, 2019 at 21:38 UTC | |
by ovedpo15 (Pilgrim) on Aug 06, 2019 at 07:01 UTC | |
by afoken (Chancellor) on Aug 06, 2019 at 08:30 UTC | |
by holli (Abbot) on Aug 06, 2019 at 10:48 UTC | |
by bliako (Abbot) on Aug 06, 2019 at 15:36 UTC | |
by afoken (Chancellor) on Aug 06, 2019 at 20:19 UTC | |
| |
by Marshall (Canon) on Aug 09, 2019 at 08:23 UTC |