如何复制具有给定扩展名的所有文件?

时间:2009-11-03 11:48:26

标签: perl

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

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

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

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

2 个答案:

答案 0 :(得分:5)

试试这个:

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

答案 1 :(得分:3)

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

相关问题