PHP implementation to traverse the current folder and all the files and folders under the code, the main use of recursion, there is a need for friends, you can refer to the study.
The code is as follows:
‘;
function Getdir ($path)
{
if (!is_dir ($path)) return;
$handle = Dir ($path);
while ($file = $handle->read ())
{
if ($file! = '. ' && $file! = ' ... ')
{
$path 2 = $path. ' /'. $file;
if (Is_dir ($path 2))
{
echo $file. " \ t ";
Getdir ($path 2);
}else
{
echo $file. ";
}
}
}
}
Getdir ($path);
Echo '
‘;
function Get_dir_scandir ($path) {
$tree = Array ();
foreach (Scandir ($path) as $single) {
if ($single! = '. ' && $single! = ' ... ')
{
$path 2 = $path. ' /'. $single;
if (Is_dir ($path 2))
{
echo $single. "\ r \ n";
Get_dir_scandir ($path 2);
}else
{
echo $single. "\ r \ n";
}
}
}
}
Get_dir_scandir ($path);
Echo '
‘;
function Get_dir_glob () {
$tree = Array ();
foreach (Glob ('./curl/* ') as $single) {
echo $single. "\ r \ n";
}
}
Get_dir_glob ();
Echo '
‘;
function Myscandir ($path)
{
if (!is_dir ($path)) return;
foreach (Scandir ($path) as $file)
{
if ($file! = '. ' && $file! = ' ... ')
{
$path 2= $path. ' /'. $file;
if (Is_dir ($path 2))
{
Echo $file;
Myscandir ($path 2);
}else
{
echo $file. ' ‘;
}
}
}
}
Myscandir ($path);
Echo '
‘;
function Myglob ($path)
{
$path _pattern = $path. ' /*‘;
foreach (Glob ($path _pattern) as $file)
{
if (Is_dir ($file))
{
Echo $file;
Myscandir ($file);
}else
{
echo $file. '
‘;
}
}
}
Myglob ($path);
?>
Article by http://nk.39.net/shjl/nszx/index.html finishing release
Code for the PHP traversal folder and all files under it