perl 删除一个非空目录方法 - IDC资讯网_站长学院 - Java PHP Flex Python Ajax CSS 编程 开源 学习 总结 分享

#如何调用
deleteFolder("test");

#Used to remove a directory which is not empty.
#the process function.
sub deleteFolder{
  my $path = $_[0];
  chdir $path;

  #get all the files in that directory.
  @_=<*>;
  for(@_){
    if(-d $_){
      #if the destination file is a directory, go recursion.
      deleteFolder($_);
    }else{
      unlink;
    }
  }

  #Go up and del the destination directory.
  chdir "../";
  rmdir $path;
}
 
编程语言 | 评论(0) | 引用(0) | 阅读(5279)