Note: Visitfile () has minor modifications
Copy the Code code as follows:
View files for a specified folder
$fileList = Array ();
function Visitfile ($path)
{
Global $fileList;
$path = str_replace ("\ \", "/", $path);
$fdir = Dir ($path);
while (($file = $fdir->read ())!== false)
{
if ($file = = '. ' | | $file = = ' ... ') {continue;}
$pathSub = Preg_replace ("*/{2,}*", "/", $path. " /". $file); Replace more than one backslash
$fileList [] = Is_dir ($pathSub)? $pathSub. " /": $pathSub;
if (Is_dir ($pathSub)) {visitfile ($pathSub);}
}
$fdir->close ();
return $fileList;
}
?>
if (!empty ($path)) {
$path = Preg_replace ("*/{2,}*", "/", $path);
$files = Visitfile ($path);
Switch (Strtolower ($_get["Action"]))
{
Case "View":
foreach ($files as $key = $value)
{
printf ("no.%4d%s
\ r \ n ", $key +1, $value);
}
Break
Case "Delete":
$faileFiles = Array ();
foreach (Array_reverse ($files) as $value)
{
if (!unlink ($value))
{
Array_push ($faileFiles, $value);
}
}
if (!unlink ($path)) {Array_push ($faileFiles, $path);}
if (count ($faileFiles) > 0)
{
printf ("
Delete failed file (%d):
\ r \ n ", Count ($faileFiles));
foreach ($faileFiles as $key = $value)
{
printf ("no.%4d%s
\ r \ n ", $key +1, $value);
}
}
Break
}
}
?>
The above describes the Visitseoul PHP visitfile traversal of the specified folder functions, including the visitseoul aspect of the content, I hope to be interested in PHP tutorial friends helpful.