A function written in php to delete a directory

WBOY
Release: 2016-07-25 09:07:20
Original
1042 people have browsed it
  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. ?>

复制代码

>>>



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!