php 删除目录,该怎么解决

WBOY
Release: 2016-06-13 12:01:25
Original
1011 people have browsed it

php 删除目录
php删除指定目录下面的所有空的后代目录

求代码 求私思路
------解决方案--------------------
思路就是遍历,然后判断文件数量和文件夹数量为空,则删除。

用shell就简单了

find 目录 -mindepth 1 -depth -empty -type d -exec rm -r {} \;
Copy after login


用php就复杂了
<br />function rmEmptyDir($spath){<br />    if($handle = opendir($spath)){<br />        while(($file=readdir($handle))!==false){<br />            if($file!='.' && $file!='..'){<br />                $curfile = $spath.'/'.$file;<br /><br />                if(is_dir($curfile)){ // dir<br />                    rmEmptyDir($curfile);<br />                    if(count(scandir($curfile))==2){ // 空目錄<br />                        rmdir($curfile);<br />                    }<br />                }<br />            }<br />        }<br />        closedir($handle);<br />    }<br />}<br /><br />$folder = '目標文件夾';<br /><br />rmEmptyDir($folder);<br />
Copy after login

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!