php文件夹控制类,包括创建文件夹,遍历文件夹,删除文件夹功能,看代码
<?
/*
*@author luhuijie
*文件及控制类
*date:2011-9-22
*/
class dirLu{
private $arrayDir = array();
function __contruct(){
}
function __set($name,$value){
$this->$name = $value;
}
function __get($name){
return $this->$name;
}
function mkDir($dirName){
if(!$this->isDir($dirName)){
if($this->mkDir(dirname($dirName))){
mkdir($dirName,0777);
return true;}
}else{
return true;
}
}
function delDir($dirName){
if (@rmdir($dirName)==false && is_dir($dirName)) {
if ($dp = opendir($dirName)) {
while (($file=readdir($dp)) != false) {
if (is_dir($dirName."/".$file) && $file!='.' && $file!='..') {
$this->delDir($dirName."/".$file);
} elseif($file!="."&$file!="..") {
unlink($dirName."/".$file);
}
}
closedir($dp);
rmdir($dirName);
}else{
return false;
}
}
return true;
}
function listDir($dirName){
$dp = opendir($dirName);
while($filename = readdir($dp))
{
if($filename!='.'&&$filename!='..')
{ if(is_dir($dirName."/".$filename.'/')){
$this->arrayDir[] = "文件夹".$dirName."/".$filename;
$this->listDir($dirName."/".$filename);
}else{
$this->arrayDir[] = '文件'.$dirName."/".$filename;
}
}
}
return $this->arrayDir;
}
function mvDir($sorceDir,$aimDir){
}//这个有待补充。
private function isDir($dirName){
return is_dir($dirName);
}
}
$d = new dirLu();
//$d->mkDir("a/b/c/d/");
var_dump($d->listDir("a"));
?>
更多信息请查看IT技术专栏