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
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |