【问题标题】:How can I copy all files with a given extension?如何复制具有给定扩展名的所有文件?
【发布时间】:2009-11-03 11:48:26
【问题描述】:

我需要将某个目录中的所有*.exe文件复制到其他虚拟驱动器。

如果我正在编写批处理脚本,我会使用xcopy "%mycopyposition%\*.exe"

但我认为在 Perl 脚本中这将是一个坏主意。

我看到了一个File::Copy 模块,但不知道怎么做。

【问题讨论】:

  • 请阅读 perldoc File::Copy
  • 当然,你还需要遍历exe的
  • 我已经阅读了,但没有关于我的问题的信息

标签: perl


【解决方案1】:

试试这个:

use File::Copy;
for my $file (<*.exe>) {
    # Copies from directory $mycopyposition to current directory.
    copy  "$mycopyposition/$file", $file or die "copy $file failed: $!";
}

【讨论】:

  • 注意他的xcopy 复制来自 %mycopyposition% 不是。而且,当我们使用模块时,建议使用File::Spec-&gt;catfile 来连接路径。
  • 哦,对不起,我不熟悉xcopy
【解决方案2】:

我认为使用xcopy 是个好主意。它做你想做的事。此外,它还保留了时间戳和其他属性。有一些非常有用的选项。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-20
    • 1970-01-01
    • 2016-04-26
    • 2019-06-14
    相关资源
    最近更新 更多