php7如何用递归删除空文件夹
php版本7.0.4
代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
<?php
$path = 'd:/' ;
rmDir_1( $path );
function rmDir_1( $path ) {
$files = scandir( $path );
// 删除当前目录和上一级目录
foreach ( $files as $key => $file ) {
if ( $file == '.' || $file == '..' ) {
unset( $files [ $key ]);
}
}
if ( $files ) {
foreach ( $files as $file ) {
if ( is_dir ( $path . '/' . $file )) {
//echo 'dir=' . $path . '/' . $file . PHP_EOL;
rmDir_1( $path . '/' . $file );
}
}
} else {
//echo 'rmdir=' . $path . PHP_EOL;
rmdir ( $path );
}
}
?>
|
/php/27876.htmlwww.phpzy.comtrue/php/27876.htmlTechArticlephp7如何用递归删除空文件夹 php版本7.0.4 代码如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 ?php $path = 'd:/' ; rmDir_1( $path ); function rmDir_1( $path ) { $files = scandir( $path ); // 删除当前目...
相关文章
- 暂无相关文章
PHP之友评论