Skyler99 has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to copy the RTF file and not the TEXT . I cannot tell if the script is getting mix up with trying to rename the RTF and TEXT. Could you take a look at the code and let me know if I need to change anything to make it work. Thanks in advancedir: 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 (<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, 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"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Use file variables to copy and rename file.
by moxliukas (Curate) on Jun 04, 2003 at 21:39 UTC | |
|
Re: Use file variables to copy and rename file.
by Skeeve (Parson) on Jun 05, 2003 at 05:39 UTC |