首页 > 代码库 > php 自定义类 Clscandir
php 自定义类 Clscandir
class Clscandir{ public $path; public $sorting_order; public $completeFiles ; public $completeDirs ; public $files; public $dirs ; public $filesDirs ; public $completeFilesDirs ; public function __construct($path,$sorting_order=0){ $this->scandir($path , $sorting_order); $this->get_complete_filesDirs(); $this->get_complete_dirs(); return $this->filesDirs; } public function scandir($path,$sorting_order=0){ $this->path = $path ; $this->sorting_order = $sorting_order; $this->filesDirs=scandir ( $path , $sorting_order ) ; return $this->filesDirs; //sort()升序 rsort()降序 ; } public function get_complete_filesDirs(){ if(count($this->completeFilesDirs)==0){ foreach($this->filesDirs as $k => $v ){ $this->completeFilesDirs[] = $this->_format_name($this->path."/".$v); } } return $this->completeFilesDirs; } public function get_complete_dirs(){ if(count($this->completeDirs)==0){ foreach($this->completeFilesDirs as $k=>$v){ if(is_dir($v)){ $this->completeDirs[]=$v; }else{ $this->completeFiles[]=$v; } } } return $this->completeDirs; } public function get_complete_files(){ return $this->completeFiles; } private function iva(){} protected function ote(){} public function _scandir($path){ $dir = dir($path); $retarr = array( ) ; while (($file = $dir->read()) !== false) { $retarr[] = ($file) ; } $dir->close(); $retarr["cwd"]=$this->_format_name(getcwd()); return $retarr; } public function _format_name($str){ return preg_replace ( ‘/\/{1,}/‘ , ‘/‘ , str_replace ( ‘\\‘ , ‘/‘ , $str ) ) ; } public function show(){ echo "目录:<br>"; secho($this->completeDirs); echo "文件:<br>"; secho($this->completeFiles); } public function demo(){ echo str_replace(array("\n"," "),array("<br>"," "), htmlspecialchars(‘ $dir=_default_em($_REQUEST["dir"],\"I:/AppServ/www/_doll/"); $scandir=new CLsandir($dir,0); secho($scandir->get_complete_dirs()); secho($scandir->get_complete_files());‘) ) ; } public function each($arr,$callback=""){ if(!is_array($arr))return ‘Is not array!‘; $retarr=array(); foreach($arr as $k=>$v){ if(""!=$callback) {$retarr[$k]=$callback($v); } else {$retarr[$k]=$v;} } return $retarr; } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。