use strict; use File::Copy; use File::Basename; use File::Path; use File::Glob ':glob'; my $din = 'c:/temp/origin/'; my $dout = 'c:/temp/destination/'; docp($din,$dout,1); sub docp { my $din = shift(); # ORIGIN DIRECTORY my $dout = shift(); # DESTINATION DIRECTORY my $tree = shift(); # DEPTH OF DIRECTORY RECURSION my ($f,$d,$b); die if -e $dout; mkpath($dout); my @list = bsd_glob($din."*"); map { ($f,$d) = fileparse($_); if (-d and $tree) { $f = $f.'/'; $b = $_.'/'; docp($b,$dout.$f,$tree) if $tree ge 0; } else { copy ($_,$dout.$f); } } @list; $tree = $tree - 1; }