


PHP implements a recursive function for deleting an entire directory_PHP tutorial
Jul 13, 2016 am 10:03 AMphp implements the recursive function for deleting the entire directory
This article mainly introduces the php implementation of the recursive function for deleting the entire directory, involving php recursive algorithm and directory operation skills , friends in need can refer to it
The example in this article describes the PHP implementation of a recursive function for deleting an entire directory. Share it with everyone for your reference. The specific implementation method is as follows:
?
3 4 513 14
15
16
17
|
<?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);<🎜> <🎜>?> |

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
