色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

php 目錄遍歷、刪除 函數(shù)的使用介紹

小編今天沒(méi)事寫(xiě)了目錄想關(guān)的函數(shù) 

   包括 遍歷該文件夾下的文件,目錄子目錄  讀取當(dāng)前文件下目錄和文件  刪除當(dāng)前文件夾下的目錄子目錄以及文件 以上三個(gè)函數(shù)目前還不支持中文文件 中文目錄
復(fù)制代碼 代碼如下:
<?php
header("Content-type:text/html;charset=utf-8");
/**
* 讀取當(dāng)前目錄下的文件和目錄
*
* @param    string    $path    路徑
* @return    array    所有滿(mǎn)足條件的文件
*/
function tlist($path){
    $path = iconv('utf-8', 'gbk', $path);
    if(!is_dir($path)){
        throw new Exception($path."不是目錄");
    }
    $arr = array('dir'=>array(),'file'=>array());
    $hd = opendir($path);
    while(($file = readdir($hd))!==false){
        if($file=="."||$file=="..") {continue;}
        if(is_dir($path."/".$file)){
            $arr['dir'][] = iconv('gbk','utf-8',$file);
        }else if(is_file($path."/".$file)){
            $arr['file'][] = iconv('gbk','utf-8',$file);
        }
    }
    closedir($hd);
    echo "目錄有:".implode("<br />",$arr['dir'])."<br />";
    echo "文件有:".implode("<br />",$arr['file']);
}
/**
* 遍歷當(dāng)前目錄下的文件和目錄以及子文件夾中目錄
*
* @param    string    $path    路徑
* @return    array    所有滿(mǎn)足條件的文件
*/
function blist($path){
    if(!is_dir(iconv("utf-8","gbk",$path))){
    throw new Exception("文件夾".$path."不存在或者不是文件");
   }
    $arr = array();
    $hd = opendir(iconv("utf-8","gbk",$path));
    while(($file = readdir($hd))!==false){
        if($file=="."||$file=="..") {continue;}
          $newpath=iconv('utf-8', 'gbk', $path) .'/'.$file;
        if(is_dir($newpath)){
            $arr[] = blist($path."/".$file);
        }else if(is_file($newpath)){
            $arr[] = iconv('gbk','utf-8',$file);
        }
    }
    closedir($hd);
    return $arr;
}
/**
* 刪除目錄下的文件以及子目錄
* #param  string $path 路徑
* #return string 刪除成功返回true 失敗返回false;
*/
function dirDel($path){
    if(!is_dir($path)){
        throw new Exception($path."輸入的不是有效目錄");
    }
    $hand = opendir($path);
    while(($file = readdir($hand))!==false){
        if($file=="."||$file=="..")  continue;
        if(is_dir($path."/".$file)){
            dirDel($path."/".$file);
        }else{
            @unlink($path."/".$file);
        }

    }
    closedir($hand);
    @rmdir($path);
}
?>

php技術(shù)php 目錄遍歷、刪除 函數(shù)的使用介紹,轉(zhuǎn)載需保留來(lái)源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 团风县| 永顺县| 康平县| 道孚县| 邹城市| 调兵山市| 博湖县| 平南县| 保康县| 龙口市| 绵竹市| 龙门县| 湖南省| 山阴县| 山丹县| 明溪县| 香格里拉县| 乌拉特前旗| 全南县| 阳江市| 大埔区| 娄烦县| 田东县| 上林县| 泸溪县| 青岛市| 新昌县| 东光县| 建水县| 云梦县| 济源市| 汶上县| 大兴区| 泸州市| 青浦区| 邻水| 桦川县| 云浮市| 平凉市| 清原| 科尔|