Home > Backend Development > PHP Tutorial > PHP7 implements sample code for deleting empty folders based on recursion

PHP7 implements sample code for deleting empty folders based on recursion

怪我咯
Release: 2023-03-12 18:00:01
Original
1230 people have browsed it

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

This article describes the method of deleting empty folders based on recursion in php7. Share it with everyone for your reference, the details are as follows:

php version 7.0.4

The code is as follows:

<?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

The above is the detailed content of PHP7 implements sample code for deleting empty folders based on recursion. 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