dir: C:\Apps\Impac\Db\Escribe\07\00002A0F.002 file: newfile:270917 dir: C:\Apps\Impac\Db\Escribe\07\00002A0F.002 file:STATUS.TXT newfile: 270917 dir: C:\Apps\Impac\Db\Escribe\07\00002A0F.002 file:WORD1.RTF newfile:2 70917 Failed to copy Word1.rtf: No such file or directory #### #! perl -w use strict; use File::Copy; my $infile = "c:/zip files misc/doclisth.chr"; open IN, "<$infile" or die "Couldn't open $infile, $!"; while () { chomp; my @fields = split /,/; my $newfile = $fields[0]; my $path_str = $fields[13]; do { warn "Empty field 14"; next } unless $path_str; my @path = split /\\/, $path_str; my $dir = join "\\", @path[ 0, 1, 2, 3, 4, 5, 6 ]; process_dir($dir,$newfile); } close IN; sub process_dir { my ($dir, $newfile) = @_; do { warn "$dir does not exist!\n"; return } unless -e $dir; opendir DIR, $dir or do { warn "Could not open $dir $!\n" ; return }; while ( my $file = readdir DIR ) { print "dir: $dir file:$file newfile:$newfile\n"; #before the next unless statements. next unless -f "$dir\\$file"; next unless $file =~ m/\.rtf$/; copy( "$dir\\$file", "C:\\testfiles\\$newfile" ) or die "Failed to copy $file: $!\n"; } }