[Perl]如何复制档案及目录

use File::Copy;
copy('file1.txt','file2.txt') or die "can't copy: $!\n";

复制目录

sub copy_dir{
  my $source = $_[0];
  my $target = $_[1];
  use File::Copy;
  opendir(DIR,$source);
  while(my $filename = readdir(DIR)){
    if(-f "$source/$filename")){
      copy("$source/$filename","$target/$filename") or die "can't copy: $!\n";
    }
  }
  close(DIR);
}

参考网页

  • File::Copy - Copy files or filehandles
    1. No comments yet.

    1. No trackbacks yet.

    return top

    %d 位部落客按了赞: