Home  >  Article  >  Backend Development  >  PHP deletes a directory and all subordinate directories and file codes within the directory

PHP deletes a directory and all subordinate directories and file codes within the directory

WBOY
WBOYOriginal
2016-07-25 08:42:20703browse
  1. //PHP deletes the directory and all subordinate directories and file codes in the directory
  2. function delDir( $dirName='' ){
  3. if ( $handle = opendir( "$dirName" ) ) {
  4. while ( false ! == ( $item = readdir( $handle ) ) ) {
  5. if ( $item != "." && $item != ".." ) {
  6. if ( is_dir( "$dirName/$item" ) ) {
  7. $this->delDir( "$dirName/$item" );
  8. } else {
  9. unlink( "$dirName/$item" );
  10. }
  11. }
  12. }
  13. closedir( $handle );
  14. }
  15. }
  16. delDir('directory');
Copy code

PHP


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