PHP visitfile () traverse the specified folder function _php Tutorial

Source: Internet
Author: User
Note: Visitfile () has minor modifications
Copy CodeThe code is 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
}
}
?>

http://www.bkjia.com/PHPjc/322470.html www.bkjia.com true http://www.bkjia.com/PHPjc/322470.html techarticle Note: Visitfile () has a few modifications copy code code as follows:?//view File $fileList = Array () for the specified folder, function Visitfile ($path) {global $fileList; $path = Str_replace ( ...

  • 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.