skyler has asked for the wisdom of the Perl Monks concerning the following question:
use File::Find; use File::Copy; sub find_copy_rename { my @dir = $fixed_path; my @get_directory = substr($fixed_path,-12); my $get_each_directory = @get_directory; my $dir = @dir; my $current_path = 'C:\\temp\\'; if ($File::Find::dir ne $dir) { $File::Find::prune = 1; return 0; } return 0 if ($_ !~ /\.rtf$/); copy($File::Find::name, $current_path.$_) or die "Failed to copy $ +_: $!\n"; return 1; } find(\&process_files, $dir); my @process_file = &process_files; my $get_files = grep { !-d } @process_file; foreach my $get_files (@process_file) { my $newfile = $get_files; $newfile =~ s/\$mrn.$get_each_directory.'.'.rtf$/word1.rtf/; if (-e $newfile) { warn "can't rename $get_files to $newfile: $newfile exists\n"; } elsif (rename "$newdir/$get_files", "$newdir/$newfile") { print "file was renamed to $newfile\n" } else { warn "rename $get_files to $newfile failed: $!\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Find, copy & rename
by blokhead (Monsignor) on Feb 24, 2003 at 05:20 UTC | |
by skyler (Beadle) on Feb 24, 2003 at 05:32 UTC | |
by CountZero (Bishop) on Feb 24, 2003 at 12:30 UTC | |
|
Re: Find, copy & rename
by CountZero (Bishop) on Feb 24, 2003 at 07:31 UTC | |
|
Re: Find, copy & rename
by Thelonius (Priest) on Feb 24, 2003 at 15:00 UTC |