php遞歸刪除目錄下的所有文件:
<?php
header("content-type:text/html;charset=utf-8");
/**
*刪除指定目錄()刪除子目錄和文件
*@path 文件目錄路徑 string
*@return void
*/
function hello($path){
//1:判斷刪除目錄是否存在
if(!file_exists($path)){
return false;
}
//2:將目錄內容全部獲取出
$list = scandir($path);
//3:遍歷目錄
foreach($list as $f){
//4:將 . .. 排除在外
if($f != '.' && $f != '..'){
//5:如果內容文件 unlink
if(is_file($path."/".$f)){
unlink($path.".".$f);
}else{
//6:目錄 遞歸
hello($path."/".$f);
}
}
}//foreach end
//7:循環外刪除目錄!!
rmdir($path);
}
?>
php遞歸便利出目錄下的所有文件:
URL:http://www.bianceng.cn/webkf/PHP/201410/45952.htm
<?php
header('content-type:text/html;charset=gbk');
ini_set("date.timezone", "Asia/Chongqing");
/*
* 遍歷一個指定目錄()包括子目錄和文件
* @param string $path 指定目錄名稱
* @return viod
*/
class dir{
function upl($path){
//判斷處理的目錄是否存在 不存在 return false;
if(!file_exists($path)){
return false;
}
//列出當前目錄內容
$list=scandir($path);
foreach($list as $f){
//去除 . ..
if($f!='.'&&$f!='..'){
//判斷是否是一個目錄【$path.'/'.$f】
if(is_dir($path."/".$f)){
//輸出
echo $path."/".$f."<br />";
//遞歸調用自己
$this->upl($path."/".$f);
}else{
//如果文件存在輸出
echo $path."/".$f."<br />";
}
}//if end
}//foreach end
}
}
$a=new dir();
$a->upl("d:/www/guo/application");