PHP类封装,如何实现递归显示删除指定目录下所有文件及空目录?
- 内容介绍
- 文章标签
- 相关推荐
本文共计133个文字,预计阅读时间需要1分钟。
phpclass File{ static public function ShowDir($path, $level=0) { $dir=opendir($path); while (($file=readdir($dir)) !==false) { if ($file !=='.' && $file !=='..') { $filepath=$path . '/' . $file; for ($i=0; $i < $level * 5; $i++) { echo ; } echo $file . \n; } } }}
<无详细内容><?php class file{ static public function ShowDir($path,$level=0){ $dir=opendir($path); while(($file=readdir($dir)) !==false){ if($file!='.' && $file!='..'){ $filepath=$path.'/'.$file; for($i=0;$i<$level*5;$i++){ echo " "; } echo $file.'<br>'; if(is_dir($filepath)) { static::ShowDir($filepath, $level + 1); } } } closedir($dir); } static public function DeleteDir($path){ $dir=opendir($path); while(($file=readdir($dir)) !== false){ if($file!='.' && $file!='..'){ $filepath=$path.'/'.$file; if(is_dir($filepath)){ self::DeleteDir($filepath); }else{ unlink($filepath); } } } closedir($dir); rmdir($path); } } ?>
本文共计133个文字,预计阅读时间需要1分钟。
phpclass File{ static public function ShowDir($path, $level=0) { $dir=opendir($path); while (($file=readdir($dir)) !==false) { if ($file !=='.' && $file !=='..') { $filepath=$path . '/' . $file; for ($i=0; $i < $level * 5; $i++) { echo ; } echo $file . \n; } } }}
<无详细内容><?php class file{ static public function ShowDir($path,$level=0){ $dir=opendir($path); while(($file=readdir($dir)) !==false){ if($file!='.' && $file!='..'){ $filepath=$path.'/'.$file; for($i=0;$i<$level*5;$i++){ echo " "; } echo $file.'<br>'; if(is_dir($filepath)) { static::ShowDir($filepath, $level + 1); } } } closedir($dir); } static public function DeleteDir($path){ $dir=opendir($path); while(($file=readdir($dir)) !== false){ if($file!='.' && $file!='..'){ $filepath=$path.'/'.$file; if(is_dir($filepath)){ self::DeleteDir($filepath); }else{ unlink($filepath); } } } closedir($dir); rmdir($path); } } ?>

