#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
use File::Copy;
use Data::Dumper;
my $SrcRootDir = 'G:/data/';
my $SrcRootDir_old = 'G:/data/old/';
my $DestRootDir = 'Z:/transfer';
my $transfer = 'Z:/transfer/transfer_list.txt';
my %file;
my %file2;
my %file3;
my ($file1, $file2);
my $Track='Z:\transfer\tracking.txt';
my $old_files='Z:\transfer\Old_Files.txt';
my $Missing_files='Z:\transfer\Missing_Files.txt';
my $Copied_files='Z:\transfer\Copied_Files.txt';
open(TRACK,">$Track");
open(MISSING_FILES,">$Missing_files");
open(COPIED_FILES,">$Copied_files");
print COPIED_FILES "getting files from list\n";
print COPIED_FILES "\n";
open(IN, '<', $transfer) or die "Could not open $transfer: $!\n";
while(<IN>) {
chomp;
# my ($filename) = ($_ =~ /^(.+)\..+$/);
my ($filename) = ($_ =~ /^(.+)(\_.+)?$/);
$file{lc($filename)}++;
print "getting files $filename\n";
}
close(IN);
find(\&wanted, $SrcRootDir);
close(TRACK);
close(COPIED_FILES);
print MISSING_FILES "These are the drawings that could not be found\n";
print MISSING_FILES "Please check for incorrect drawing numbers in list\n";
print MISSING_FILES "\n";
my %file1;
open (FILE1, 'T:\Team\transfer\tracking.txt') or die "Could not open $Track: $!\n";
while(<FILE1>) {
$file1{lc $_}=1;
}
close(FILE1);
open (FILE2, 'T:/team/transfer/transfer_list.txt') or die "Could not open $transfer: $!\n";
while (<FILE2>) {
unless ($file1{lc $_}) {
print $_;
print MISSING_FILES "$_\n";
}
}
close(FILE2);
close(MISSING_FILES);
sleep(10);
exit;
sub wanted {
if ( $File::Find::dir = /old/ )
{$File::Find::prune = 1;
return;
}
# my ($filename) = ($_ =~ /^(.+)(\.+)?$/);
my ($filename) = ($_ =~ /^(.+)\_.+$/);
# print "getting file $filename\n";
return unless exists $file{lc($filename)};
print "Copying $File::Find::name to $DestRootDir\n";
# print TRACK "$File::Find::name\n";
print TRACK "$filename\n";
print COPIED_FILES "$filename\n";
# copy($File::Find::name, "$DestRootDir/$_") or warn "Could not copy $_: $!\n";
copy($File::Find::name, "$DestRootDir/$_") or print TRACK "Could not copy $_: $!\n";
}
|