Home > Backend Development > PHP Tutorial > PHP implements a recursive function for deleting the entire directory, the entire directory is recursive_PHP tutorial

PHP implements a recursive function for deleting the entire directory, the entire directory is recursive_PHP tutorial

WBOY
Release: 2016-07-13 10:03:28
Original
911 people have browsed it

php implements a recursive function for deleting the entire directory, and the entire directory is recursive

The example in this article describes the php implementation of the recursive function for deleting the entire directory. Share it with everyone for your reference. The specific implementation method is as follows:

<&#63;php
function delete_directory($dir) {
   if ($dh = @opendir($dir)) {
     while (($file = readdir ($dh)) != false) {
       if (($file == ".") || ($file == "..")) continue;
        if (is_dir($dir . '/' . $file))
          delete_directory($dir . '/' . $file);
        else
          unlink($dir . '/' . $file);
     }
     @closedir($dh);
     rmdir($dir);
   }
}
$dir = "./fakeDir";
delete_directory($dir);
&#63;>
Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/968265.htmlTechArticlephp implements a recursive function for deleting the entire directory, and the entire directory is recursive. This example describes the php implementation for deleting the entire directory. Recursive function for directories. Share it with everyone for your reference. Specific actual...
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