php 自訂類 Clscandir

來源:互聯網
上載者:User

標籤:blog   os   檔案   io   for   cti   html   div   

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個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.