You can eliminate the if/elsif statements and reading the temp/dev_flash* files multiple times by creating a hash 'lookup' to decide which folders to copy the searched files into. For example ;

#!perl use strict; use warnings; use File::Find; use File::Copy qw(copy); use File::Path qw(make_path); use Data::Dump 'pp'; use Cwd; # search directory my $dir = $ARGV[0]; if ( not defined $dir ) { print "\nUsage: $0 dev_flash\n"; exit(0); } elsif (! -d $dir){ print "$dir does not exist\n"; exit(0); } # current working directory my $cwd = cwd(); # create lookup my %lookup=(); find(\&file_lookup,'temp'); #pp \%lookup; # scan files and copy my %report=(); find(\&file_copy,$dir); # report report_dev_flash('report.txt'); sub file_lookup { my $infile = $_; return if (-d $infile); open IN,'<',$infile or die "$! $infile"; my $count = 0; while (my $line = <IN>){ $line =~ s/^\s+//; $line =~ s/\s+$//; if ($line ne ''){ push @{$lookup{lc $line}}, $infile; ++$count; } } close IN; # create directory tree if ($count) { my $path = dupl_path($infile); make_path($path,{ verbose => 1 }); print "read $infile -- $count lines\n"; } } sub copy_path { return $cwd.'/copied_files/'.shift; } sub dupl_path { return copy_path(shift).'/duplicate'; } sub file_copy { my $file = $_; return if (-d $file); my $lcfile = lc $file; if ( exists $lookup{$lcfile} ){ for my $folder ( @{$lookup{$lcfile}} ){ my $path = copy_path($folder); if ( -e "$path/$file" ) { $path = dupl_path($folder); } #print "Copying $file, $path\n"; copy( $file, $path ) or die "$!"; push @{$report{$folder}}, $file; } } } sub report_dev_flash { my $outfile = shift; open OUT,'>',$outfile or die "$!"; for my $folder (sort keys %report){ print OUT "\n $folder |==================================>\n"; print OUT "\t$_\n" for @{$report{$folder}}; } close OUT; }

note :
There are 2 possible errors in the temp files ;
1 - dev_flash019 contains libgcm_sys.sprx.dex which does not exist
2 - libvpost.sprx appears in both dev_flash018 and dev_flash020

poj

In reply to Re: directories and sub directories and copying or moving hundereds or thousands of files :) by poj
in thread directories and sub directories and copying or moving hundereds or thousands of files :) by james28909

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.