File::Copy提供copy及move兩種方法來拷貝及移動檔案。
copy函式需要兩個參數,參數可以是字串或filehandle參考。
use File::Copy;
use strict;
usage() unless @ARGV == 2;
my $src=shift;
my $dst=shift;
die "can't find $src" unless -e $src;
copy($src, $dst) || die "copy: $!";
sub usage{
print "$0 src dest\n";
exit(1);
}

copy函式可以拷貝二元檔或文字檔,建議在拷貝二元檔時,使用檔案名稱代替filehandle。

move函式是將第一個引數的所指定檔案移動到第二個引數的所指定的檔案。
use File::Copy;
use strict;
usage() unless @ARGV == 2;
my $old_name=shift;
my $new_name=shift;
die "can't clobber $new_name" if -e $new_name;
move($old_name, $new_name);
sub usage{
print "$0 oldname newname\n";
exit(1);
}

當使用move函式時,move函式並不會提出任何警告(檔案存在是否要複蓋)。
arrow
arrow
    全站熱搜

    jck11 發表在 痞客邦 留言(0) 人氣()