skyler has asked for the wisdom of the Perl Monks concerning the following question:
#! perl -w use strict; use File::Copy; my $infile = 'c:/doclisth.chr'; open IN, "<$infile" or die "Couldn't open $infile, $!"; while (<IN>) { chomp; my @fields = split /,/; my $mrn = $fields[0]; my $path_str = $fields[13]; do { warn "Empty field 13"; next } unless $path_str; my @path = split /\\/, $path_str; my $dir = join "\\", @path[ 0, 5, 6 ]; process_dir($dir,$mrn); } close IN; sub process_dir { my $dir = shift; my $mrn = shift; 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 ) { next unless -f "$dir\\$file"; next unless $file =~ m/\.rtf$/; my $newname = rename ($file, $mrn); copy( "$dir\\$file", "C:\\testfiles\\$newname" ) or die "Failed to copy $file: $!\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Cannot Copy and Rename file
by cciulla (Friar) on Jun 03, 2003 at 01:34 UTC | |
|