Skyler99 has asked for the wisdom of the Perl Monks concerning the following question:
#! perl -w use strict; use File::Copy; my $infile = 'c:/doclist1.chr'; open IN, "<$infile" or die "Couldn't open $infile, $!"; while (<IN>) { chomp; my @fields = split /,/; my $mrn = $get_mrn[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); } close IN; sub process_dir { my $dir = 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$/; copy( "$dir\\$file", "C:\\testfiles\\$file" ) or die "Failed to copy $file: $!\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: FindCopyRename File
by Zaxo (Archbishop) on May 30, 2003 at 02:53 UTC |