【问题标题】:copying all .txt files from the CWD to another directory in perl将所有 .txt 文件从 CWD 复制到 perl 中的另一个目录
【发布时间】:2014-05-01 23:05:00
【问题描述】:

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

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

【问题讨论】:

  • 提示:使用File::Copy

标签: perl


【解决方案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>;

【讨论】:

  • @user2812535 如果有帮助,您可以通过单击答案旁边的复选标记来接受答案。请阅读accepting an answer了解更多详情。
猜你喜欢
  • 1970-01-01
  • 2013-09-28
  • 1970-01-01
  • 1970-01-01
  • 2020-12-08
  • 2017-11-18
  • 2012-02-15
相关资源
最近更新 更多