Home  >  Article  >  Backend Development  >  How to use the PHP rmdir() function to delete a directory_PHP Tutorial

How to use the PHP rmdir() function to delete a directory_PHP Tutorial

WBOY
WBOYOriginal
2016-07-15 13:32:431103browse

For

PHP rmdir() function code:

  1. < ?php
  2. function removeDir($dirName)
  3. {
  4. $result = false;
  5. if(! is_dir($dirName))
  6. {
  7. trigger_error("Directory Name error", E_USER_ERROR);
  8. }
  9. $handle = opendir($dirName);
  10. while(($file = readdir($handle)) !== false)
  11. {
  12. if($file != '.' && $file != '..')
  13. {
  14. $dir = $dirName . DIRECTORY_SEPARATOR . $file;
  15. is_dir($dir) ? removeDir($dir) : unlink($dir);
  16. }
  17. }
  18. closedir($handle);
  19. $result = rmdir($dirName) ? true : false;
  20. return $result;
  21. }
  22. ?>

and above This code is the specific use of the PHP rmdir() function.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446116.htmlTechArticleFor PHP rmdir() function code: ?php functionremoveDir($dirName) { $ result = false ; if(! is_dir($dirName)) { trigger_error(wrong directory name, E_USER_ERROR); } $ handle = opendir...
Statement:
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