Night Walker
Night Walker

Reputation: 21260

How can I copy all files with a given extension?

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 in Perl script .

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

Upvotes: 2

Views: 1291

Answers (2)

user181548
user181548

Reputation:

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: $!";
}

Upvotes: 5

Sinan &#220;n&#252;r
Sinan &#220;n&#252;r

Reputation: 118118

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.

Upvotes: 3

Related Questions