PHP Small Code----Directory read sub-files or subdirectories _php tutorial

Source: Internet
Author: User

PHP Small Code----directory to read sub-files or subdirectories


RootPath = $rootPath; if (Is_dir ($this->rootpath)) {$this->rootpath = pathinfo ($this->rootpath, Pathinfo_dirname). Directory_separator. PathInfo ($this->rootpath, pathinfo_basename); $this->opdirectory = Dir ($this->rootpath); } else {$this->errormsg = ' The directory you provided does not exist! '; $this->errorno = 1001; throw new Exception ($this->errormsg, $this->errorno); }} Private function Read ($directory, $parentPath, $modeInfo = ' mixed ', $defaultDir = False, $fullPath = False) {$dirInfo = Array (); while (FALSE!== ($childDirOrFileName = $directory->read ())) {switch ($modeInfo) {case Self::recdir_mixed:if ($defau Ltdir) {$dirInfo [] = $fullPath? $parentPath. Directory_separator. $childDirOrFileName: $childDirOrFileName; } else {if ($childDirOrFileName! = '. ' && $childDirOrFileName! = ') {$dirInfo [] = $fullPath? $parentPath. Directory_separator. $childDirOrFileName: $childDirOrFileName; }} break; Case Self::recdir_dir:if (Is_dir ($parentPath. Directory_SEPARATOR. $childDirOrFileName) {if ($defaultDir) {$dirInfo [] = $fullPath? $parentPath. Directory_separator. $childDirOrFileName: $childDirOrFileName; } else {if ($childDirOrFileName! = '. ' && $childDirOrFileName! = ') {$dirInfo [] = $fullPath? $parentPath. Directory_separator. $childDirOrFileName: $childDirOrFileName; }}} break; Case Self::recdir_file:if (Is_file ($parentPath. Directory_separator. $childDirOrFileName) {$dirInfo [] = $fullPath $parentPath. Directory_separator. $childDirOrFileName: $childDirOrFileName; } break; }} return $dirInfo; }/** * (PHP 5 >= 5.4.0)
* Get direct sub-directories or direct sub-file information under directory * @param string $modeInfo [optional]

* Returns the mode of the information in the directory * mixed returns all filenames and directory names * dir returns all directory names * file returns all filenames *

* @param bool $defaultDir [OPTIONAL]

* Whether to include the default link directory: and. * False not including * true includes *

* @param bool $fullPath [OPTIONAL]

* Whether to return path information for child files or directories * True is * false no *

* @return Array returns an array that records the information in this directory */Public function getpathdirectdirinfo ($modeInfo = ' mixed ', $defaultDir = False, $f Ullpath = False) {return $this->read ($this->opdirectory, $this->rootpath, $modeInfo, $defaultDir, $fullPath);} }//----------------------------Test-----------------------------------------header ("content-type:text/html; Charset=utf-8 "), try {$recDir = new RecDir ('./calltemp/'); $dirs = $recDir->getpathdirectdirinfo (' file ', true, true); Var_dump ($dirs);} catch (Exception $ex) {echo ' in file '. $ex->getfile (). "The first of the". $ex->getline (). ' Line error: '. $ex->getmessage (). ' ('. $ex->getcode (). ')';}

http://www.bkjia.com/PHPjc/1053347.html www.bkjia.com true http://www.bkjia.com/PHPjc/1053347.html techarticle PHP Small Code----Directory read sub-files or subdirectories? PHP class RecDir {protected $rootPath; protected $opDirectory; const recdir_mixed = MIXED; co NST recdir_dir = DIR; Const RECD ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.