use strict; use File::Copy; @ARGV = qw{E:/private/qinse E:/private/qinse1/}; my $target_path = $ARGV[0]; my $dest_path = $ARGV[1]; my @stacks; sub TraverseDir($) { my $target_path = shift; # if (!(-d $target_path)){ die "error! $target_path is not a directory";} my $ret = opendir(HFILE, $target_path); die "open dir error $target_path" if(!$ret); my @file_list = readdir(HFILE); foreach my $file_name(@file_list){ my $file_path = sprintf("%s/%s", $target_path, $file_name); if ( -d $file_path ){ if ($file_name =~ /^/./.?$/ ){ next; } else{ push @stacks, $file_path; print "push $file_path/n"; } } else{ my $dest_file_path = $dest_path.$file_name; copy ($file_path, $dest_path); } } close(HFILE); my $sub_path = pop(@stacks); if ( defined($sub_path) ){ print "pop $sub_path/n"; TraverseDir($sub_path); } } TraverseDir($target_path);