PHP recursive function traverses the method of deleting files

墨辰丷
Release: 2023-03-31 15:20:01
Original
1673 people have browsed it

This article mainly introduces the method of deleting files through PHP recursive traversal. It involves the related skills of PHP traversal file operation. It is of great practical value. Friends in need can refer to it.

The example of this article tells about PHP recursive traversal. How to delete files. The details are as follows:

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

<?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);
}
?>
Copy after login

Summary: The above is the entire content of this article, I hope it can be helpful to Everyone’s learning helps.

Related recommendations:

Implement array generation in php to generate sql statements to be executed

php for file operations And the method of string encryption

The addition, deletion, modification and query function implemented by mysql in php

The above is the detailed content of PHP recursive function traverses the method of deleting files. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!