in reply to File::Copy and wildcards
File::Find::Rule is a nice, easy to use distribution that allows you to use any valid regex (including standard glob type *.txt wildcards) to search with. Here's an example using it, along with File::Copy.
use warnings; use strict; use File::Copy; use File::Find::Rule; my $from_dir = '/home/steve/repos/berrybrew'; my $to_dir = 'out'; my @files = File::Find::Rule->file() ->name('*.txt', '*.cs') ->in($from_dir); for (@files){ copy $_, $to_dir or die $!; }
That copied all *.txt and *.cs files from one directory to another, recursively.
To disable recursion, add another chained method call:
->in($from_dir) ->maxdepth(0); # descend zero levels below root of $from_dir
|
|---|