将所有.txt文件从CWD复制到perl中的另一个目录

时间:2014-05-01 23:05:01

标签: perl

我当前工作目录中有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.

有人可以帮忙吗?我做错了什么?

1 个答案:

答案 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>;