>  기사  >  백엔드 개발  >  php写的一个删除目录的函数

php写的一个删除目录的函数

WBOY
WBOY원래의
2016-07-25 09:07:201012검색
  1. // ggarciaa at gmail dot com (04-July-2007 01:57)

  2. // I needed to empty a directory, but keeping it
  3. // so I slightly modified the contribution from
  4. // stefano at takys dot it (28-Dec-2005 11:57)
  5. // A short but powerfull recursive function
  6. // that works also if the dirs contain hidden files
  7. //
  8. // $dir = the target directory
  9. // $DeleteMe = if true delete also $dir, if false leave it alone
  10. function SureRemoveDir($dir, $DeleteMe) {

  11. if(!$dh = @opendir($dir)) return;
  12. while (false !== ($obj = readdir($dh))) {
  13. if($obj==’.’ || $obj==’..’) continue;
  14. if (!@unlink($dir.’/’.$obj)) SureRemoveDir($dir.’/’.$obj, true);
  15. }
  16. closedir($dh);

  17. if ($DeleteMe){
  18. @rmdir($dir);
  19. }
  20. }
  21. //SureRemoveDir(‘EmptyMe’, false);

  22. //SureRemoveDir(‘RemoveMe’, true);
  23. ?>
复制代码

>>>



성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.