开发者

How can I copy all files with a given extension?

开发者 https://www.devze.com 2022-12-10 06:45 出处:网络
I need to copy all *.exe files in some directory to other virtual drive . If I was writing batch script I would do xcopy \"%mycopyposition%\\*.exe\".

I need to copy all *.exe files in some directory to other virtual drive .

If I was writing batch script I would do xcopy "%mycopyposition%\*.exe".

But I think it will be a bad idea i开发者_JAVA百科n Perl script .

I seen a File::Copy module, but couldn't see how to do that.


Try this:

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


I think it is an excellent idea to use xcopy. It does what you want. Plus, it preserves time stamps and other attributes. Has some very useful options.

0

精彩评论

暂无评论...
验证码 换一张
取 消