The article is very simple. Two examples implement the PHP directory creation and recursive unlimited creation and deletion of directories. Friends in need can refer to it. We use mkdir and rddir for the example.
The following is the program code:
代码如下 |
复制代码 |
function mkdirs($dir)
{
if(!is_dir($dir))
{
if(!mkdirs(dirname($dir))){
return false;
}
if(!mkdir($dir,0777)){
return false;
}
}
return true;
}
mkdirs('div/css/layout');
|
Same idea, PHP uses rmdir and unlink to recursively delete multi-level directories:
The code is as follows
代码如下 |
复制代码 |
function rmdirs($dir)
{
$d = dir($dir);
while (false !== ($child = $d->read())){
if($child != '.' && $child != '..'){
if(is_dir($dir.'/'.$child))
rmdirs($dir.'/'.$child);
else unlink($dir.'/'.$child);
}
}
$d->close();
rmdir($dir);
}
|
|
Copy code |
|
function rmdirs($dir)
{
$d = dir($dir);
while (false !== ($child = $d->read())){
if($child != '.' && $child != '..'){
if(is_dir($dir.'/'.$child))
rmdirs($dir.'/'.$child);
else unlink($dir.'/'.$child);
}
}
$d->close();
rmdir($dir);
}
http://www.bkjia.com/PHPjc/631669.htmlwww.bkjia.comtrue
http: //www.bkjia.com/PHPjc/631669.htmlThe article is very simple. Two examples implement PHP directory creation and recursive unlimited creation and deletion of directories. Friends in need For reference, we use mkdir and rddir for examples. Below...