我当前工作目录中有5个.txt文件要转移到perl中的另一个目录,但它无法正常工作。这是我的代码:
my $current_dir = Cwd::cwd();
my $dest_dir = "Path_to_destination";
system("/bin/cp \"$current_dir\/*.txt\" \"$dest_dir\"");
出于某种原因,我收到此错误消息:
/bin/cp: cannot state `Path to current working directory/*.txt': no such file or directory.
有人可以帮忙吗?我做错了什么?
答案 0 :(得分:1)
简化:
system("/bin/cp *.txt $dest_dir");
或者只使用File::Copy
use strict;
use warnings;
use File::Copy;
...
copy($_, $dest_dir) or die "Can't copy $_: $!" for <*.txt>;