Right now, I am using something like
copy catfile($PATH1, "instructions.txt"), catfile($ENV{'DIRWORK'});
individually for each of the .txt
files that I want to copy. This code is portable as it does not use any OS specific commands.
How can I copy all the text files from $PATH1
to DIRWORK
, when I do not know the individual names of all the files, while keeping the code portable?
You can use the core File::Copy
module like this:
use File::Copy;
my @files = glob("$PATH1/*.txt");
for my $file (@files) {
copy($file, $ENV{DIRWORK}) or die "Copy failed: $!";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With