Php教程: 目录遍历、删除函数的使用PHP 面向对象之成员方法知识 Php教程: 目录遍历、删除函数的使用 包括 遍历该文件夹下的文件,目录子目录 读取当前文件下目录和文件 删除当前文件夹下的目录子目录以及文件 以上三个函数目前还不支持中文文件 中文目录 复制代码 代码如下: array(),'file'=>array()); $hd = opendir($path); while(($file = readdir($hd))!==false){ if($file=="."||$file=="..") {continue;} if(is_dir($path."/...
PHP 面向对象之成员
知识 Php教程: 目录遍历、删除函数的使用 包括 遍历该文件夹下的文件,目录子目录 读取当前文件下目录和文件 删除当前文件夹下的目录子目录以及文件 以上三个函数目前还不支持中文文件 中文目录 复制代码 代码如下: 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("
",$arr['dir'])."
"; echo "文件有:".implode("
",$arr['file']); } /** * 遍历当前目录下的文件和目录以及子文件夹中目录 * * @param string $path 路径 * @return array 所有满足条件的文件 */ 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教程: 目录遍历、删除函数的使用】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。