求一个PHP函数,遍历目录包括子目录,如果文件夹下有html文件则删除。 <?php//PHP遍历文件夹下所有文件$handle=opendir('.'); //这里输入其它路径echo "目录 handle: $handle\n";echo "文件:\n";while ($file = readdir($handle)) { $a = explode('.',$file); if($a[1] == 'html' || $a[1] == 'hmt') { unlink($file); }}closedir($handle); ?> 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 遇到all.html这个名字的文件夹怎么办呢? 会楼上的用is_dir返回值bool 我自己搜了一个function tree($directory) { $mydir=dir($directory); echo "<ul>\n"; while($file=$mydir->read()){ if((is_dir("$directory/$file")) AND ($file!=".") AND ($file!="..")) {echo "<li><font color=\"#ff00cc\"><b>$file</b></font></li>\n"; tree("$directory/$file"); } else{ $a = explode('.',$file); if($a[1] == 'html' || $a[1] == 'htm') { //unlink($file); echo "<li>$file</li>\n"; } } }echo "</ul>\n"; $mydir->close(); } //开始运行echo "<h2>目录为粉红色</h2><br>\n"; tree("./"); file_get_contents获取XML的奇怪问题 msession模块是搞啥功能的?是不是存session的? 为什么会出现这个参数??index.php?PHPSESSID=37a7c28646515ef399cff97f3d8b6296 mysql语句求助 这样做法的可信任程度多少的? PHP中有没有类似charCodeAt(i)的功能的函数? 用fopen时出错,请教 请问PHP的安装问题!! 高手进来看看:(((((())))(在线等了!!!) 怎样设计同一 IP 多次点击无效? PHP 函数提问 安装配置Apache2.0.59+PHP5.1.6出现问题
用is_dir
返回值bool
function tree($directory)
{
$mydir=dir($directory);
echo "<ul>\n";
while($file=$mydir->read()){
if((is_dir("$directory/$file")) AND ($file!=".") AND ($file!=".."))
{echo "<li><font color=\"#ff00cc\"><b>$file</b></font></li>\n";
tree("$directory/$file");
}
else{
$a = explode('.',$file);
if($a[1] == 'html' || $a[1] == 'htm')
{
//unlink($file);
echo "<li>$file</li>\n";
}
}
}
echo "</ul>\n";
$mydir->close();
}
//开始运行echo "<h2>目录为粉红色</h2><br>\n";
tree("./");