You should try:copy( "$dir\\$file", "C:\\testfiles\\$file" ) or die "Failed to copy $file: $!\n"; rename $file, $newfile
But have you ever tried this:copy( "$dir\\$file", "C:\\testfiles\\$file" ) or die "Failed to copy $file: $!\n"; rename "C:\\testfiles\\$file", "C:\\testfiles\\$newfile";
Question: What will happen if you copy more than one file from $dir?copy( "$dir\\$file", "C:\\testfiles\\$newfile" ) or die "Failed to copy $file: $!\n";
Answer: You will end up with just one $newfile.
Then regarding your not-shifted $newfile parameter to your sub. Instead of shifting a sub's parameters I prefer to write:
sub process_dir { my ($dir, $newfile) = @_;
In reply to Re: Copy and Rename file at destination directory
by Skeeve
in thread Copy and Rename file at destination directory
by Skyler99
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |