Home > php教程 > php手册 > body text

php目录创建与递归无限创建和删除目录实现代码

WBOY
Release: 2016-06-13 10:00:40
Original
960 people have browsed it

文章很简单二个实例实现了php目录创建与递归无限创建和删除目录功能,有需要的朋友可以参考一下,我们用的是mkdir,rddir来实例的。

下面是程序代码:

 代码如下 复制代码
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');

同样的思路,php用rmdir和unlink递归删除多级目录的代码:

 代码如下 复制代码

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);
}

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template