Home  >  Article  >  Backend Development  >  PHP recursive traversal method to delete files, _PHP tutorial

PHP recursive traversal method to delete files, _PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:56:56711browse

The method of php recursively traversing and deleting files,

The example in this article describes the method of php recursively traversing and deleting files. Share it with everyone for your reference. The details are as follows:

With slight modifications, this function can be turned into a recursive file copy function

<&#63;php
function mover($src,$dst) {
$handle=opendir($src);
// Opens source dir.
if (!is_dir($dst)) mkdir($dst,0755);
// Make dest dir.
while ($file = readdir($handle)) {
  if (($file!=".") and ($file!="..")) {
  // Skips . and .. dirs
    $srcm=$src."/".$file;
    $dstm=$dst."/".$file;
    if (is_dir($srcm)) {
    // If another dir is found
     mover($srcm,$dstm);
  // calls itself - recursive WTG
    } else {
     copy($srcm,$dstm);
     unlink($srcm);
  // Is just a copy procedure is needed
    } // comment out this line
  }
}
closedir($handle);
rmdir($src);
}
&#63;>

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/985261.htmlTechArticleHow to delete files by php recursive traversal. This example describes the method of deleting files by php recursive traversal. Share it with everyone for your reference. The details are as follows: This function can be modified slightly...
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