目标操作
chdir 目录移动
glob 文件通配符
<> 是另一种通配符
删除操作
例:
#!/usr/bin/perl -w
my $successful = unlink "b","c","d";
print "I delete $successful file(s) just now \n";
例2:循环删除
foreach my $file (qw(b c d)){
unlink $file or warn "failed on $file:$!\n";
}
例3:创建目录并附权限
my ($name,$perm)= @ARGV; #从外界获得
mkdir $name ,oct($perm) or die "connot create $name:$!";
例4:循环删除目录
foreach my $dir (qw( aa aab )){#以后目录组成数组
rmdir $dir or warn "cannot rmdit $dir: $!";
}
例5:创建, 进入,重命名(mv),删除目录中的文件,删除目录
my $temp_dir = "/opt/perl/bb_$$";
mkdir $temp_dir ,0750 or die "cannot create $temp_dir:$!";
chdir $temp_dir;
print "cd the $temp_dir\n";
rename "/opt/perl/a" , "$temp_dir/a.perl";
print "mv a to the $temp_dir\n";
unlink glob "$temp_dir/* $temp_dir/.*";
print "unlink the file from $temp_dir\n";
rmdir $temp_dir;
print "rm the $temp_dir\n";
阅读(953) | 评论(0) | 转发(0) |