Skyler99 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 $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, 5, 6 ]; process_dir($dir,$newfile); } 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"; rename $file, $newfile or die "Can't rename '$file' to '$newfile': $!\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Copy and Rename file at destination directory
by pzbagel (Chaplain) on Jun 04, 2003 at 04:31 UTC | |
by Skyler99 (Novice) on Jun 04, 2003 at 04:43 UTC | |
by pzbagel (Chaplain) on Jun 04, 2003 at 04:55 UTC | |
|
Re: Copy and Rename file at destination directory
by Skeeve (Parson) on Jun 04, 2003 at 05:36 UTC | |
by Skyler99 (Novice) on Jun 04, 2003 at 12:36 UTC | |
by nimdokk (Vicar) on Jun 04, 2003 at 12:52 UTC |