Home >Backend Development >PHP Tutorial >PHP recursive directory traversal implementation program_PHP tutorial
PHP itself has a readdir function, but it can only read the current directory. Based on this function, I wrote another function to achieve my needs. The principle of the function is very simple, mainly using recursive calls.
The code is as follows
|
Copy code
|
||||||||
class listdir{
var $depth;
$this->tostring=””; $this->getlist($path); }else{ $this->list[$this->depth][]=$item;
}
}
}
$this->list[$this->depth]['directory']=$dir;
$this->depth-=1;
$d->close();
return $this->list;
}
//Character channeling result
function tostring($dir=""){
if($dir==””)$dir=$this->dirname;
$d=@dir($dir);
$this->tostring.=”
Statement: The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn Previous article:PHP regular expression verification email_PHP tutorialNext article:PHP regular expression verification email_PHP tutorial Related articlesSee more |