Home > Backend Development > PHP Tutorial > PHP recursively delete directories (folders)_PHP tutorial

PHP recursively delete directories (folders)_PHP tutorial

WBOY
Release: 2016-07-20 11:08:39
Original
1088 people have browsed it

Two examples of PHP recursive deletion of directories (folders) are given below. One is the code to delete a single empty directory, and the other is the code to delete directory folders in batches.

php tutorial Recursively delete directories (folders) Two examples are given below, one is the code to delete a single empty directory, and the other is the code to delete directory folders in batches.

//Delete a single empty folder

$dir = 'www.bkjia.com';
if( is_dir( $dir ) ) // Determine whether it is a directory
{
if( rmdir( $dir ) )
{
echo 'Directory deleted successfully';
}
else
{
echo 'The directory was not deleted Permissions';
}
}
else
{
echo 'is not a valid directory';
}

//Let’s look at one Function to delete directories recursively in batches.

function deletedir($dir){
if(!handle=@opendir($dir)){ //Check whether the directory to be opened exists
die("There is no such directory");                                                 deletedir($file);
U> if (@unlink ($ file)) {
echo "file & lt; b & gt; $ file & lt;/b & gt; delete success. ;b>$fileDelete failed!
";
                                           ir)){
echo "Directory< ;b>$dirDeletion successful.
n";
}else{
";
}
}



//Test program
$dir="/var/www/test";
deletedir($dir);





http://www.bkjia.com/PHPjc/444866.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/444866.html
TechArticle

php recursively delete directories (folders). Two examples are given below. One is to delete a separate empty directory code. One is the code to delete directory folders in batches. PHP tutorial recursively delete directories...
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