1. Recursively get the number of files in the directory
function Getfilecount ($dir)
{
if (!is_dir ($dir))
return false;
Open Directory
$handle = Opendir ($dir);
static $i = 0;
while (false!== $file = Readdir ($handle))
{
if ($file! = '. ' && $file!== ')
{
$file = $dir. Directory_separator. $file;
Determine if the current file is a directory
if (Is_dir ($file))
{
GetFileCount2 ($file);
}else
$i + +;
}
}
Closedir ($handle);
return $i;
}
2. Recursively get the size of the directory
function GetFileSize ($dir)
{
if (!is_dir ($dir))
return false;
Open Directory
$handle = Opendir ($dir);
static $num = 0;
while (false!== $file = Readdir ($handle))
{
if ($file! = '. ' && $file!== ')
{
$file = $dir. Directory_separator. $file;
Determine if the current file is a directory
if (Is_dir ($file))
{
GetFileSize ($file);
}else
$num + = FileSize ($file);
}
}
Closedir ($handle);
return $num;
}
PHP file Operations