Home > Backend Development > PHP Tutorial > Detailed explanation of the method of deleting empty folders based on recursion in php7

Detailed explanation of the method of deleting empty folders based on recursion in php7

墨辰丷
Release: 2023-03-27 09:26:01
Original
1287 people have browsed it

This article mainly introduces the method of deleting empty folders based on recursion in php7. It analyzes the recursive directory traversal and judgment, deletion and other related operation skills of php7 based on specific examples. Friends in need can refer to it

<?php
$path = &#39;d:/&#39;;
rmDir_1($path);
function rmDir_1($path) {
  $files = scandir($path);
// 删除当前目录和上一级目录
  foreach($files as $key => $file) {
    if ( $file == &#39;.&#39; || $file == &#39;..&#39;) {
      unset($files[$key]);
    }
  }
  if ($files) {
    foreach($files as $file) {
      if (is_dir($path . &#39;/&#39; . $file)) {
        //echo &#39;dir=&#39; . $path . &#39;/&#39; . $file . PHP_EOL;
        rmDir_1($path . &#39;/&#39; . $file);
      }
    }
  } else {
    //echo &#39;rmdir=&#39; . $path . PHP_EOL;
    rmdir($path);
  }
}
?>
Copy after login



Related recommendations:

php7 based on recursive implementationDelete empty filesFolder method example code

PythonHow to delete empty files and empty folders

php7Delete What should I do with the empty file folder?


The above is the detailed content of Detailed explanation of the method of deleting empty folders based on recursion in php7. 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