php递归遍历出文件夹下的所有文件和删除文件夹下的所有文件php
PHP递归删除目录下的所有文件:
<?php
header("content-type:text/html;charset=utf-8");
/**
*删除指定目录()删除子目录和文件
*@path 文件目录路径 string
*@retu...
PHP递归删除目录下的所有文件:
<?php
header("content-type:text/html;charset=utf-8");
/**
*删除指定目录()删除子目录和文件
*@path 文件目录路径 string
*@return void
*/
function hello($path){
//1:判断删除目录是否存在
if(!file_exists($path)){
return false;
}
//2:将目录内容全部获取出
$list = scandir($path);
//3:遍历目录
foreach($list as $f){
//4:将 . .. 排除在外
if($f != '.' && $f != '..'){
//5:如果内容文件 unlink
if(is_file($path."/".$f)){
unlink($path.".".$f);
}else{
//6:目录 递归
hello($path."/".$f);
}
}
}//foreach end
//7:循环外删除目录!!
rmdir($path);
}
?>
php递归遍历出目录下的所有文件:
<?php
header('content-type:text/html;charset=gbk');
ini_set("date.timezone", "Asia/Chongqing");
/*
* 遍历一个指定目录()包括子目录和文件
* @param string $path 指定目录名称
* @return viod
*/
class dir{
function upl($path){
//判断处理的目录是否存在 不存在 return false;
if(!file_exists($path)){
return false;
}
//列出当前目录内容
$list=scandir($path);
foreach($list as $f){
//去除 . ..
if($f!='.'&&$f!='..'){
//判断是否是一个目录【$path.'/'.$f】
if(is_dir($path."/".$f)){
//输出
echo $path."/".$f."<br />";
//递归调用自己
$this->upl($path."/".$f);
}else{
//如果文件存在输出
echo $path."/".$f."<br />";
}
}//if end
}//foreach end
}
}
$a=new dir();
$a->upl("d:/www/guo/application");
<?php
header("content-type:text/html;charset=utf-8");
/**
*删除指定目录()删除子目录和文件
*@path 文件目录路径 string
*@return void
*/
function hello($path){
//1:判断删除目录是否存在
if(!file_exists($path)){
return false;
}
//2:将目录内容全部获取出
$list = scandir($path);
//3:遍历目录
foreach($list as $f){
//4:将 . .. 排除在外
if($f != '.' && $f != '..'){
//5:如果内容文件 unlink
if(is_file($path."/".$f)){
unlink($path.".".$f);
}else{
//6:目录 递归
hello($path."/".$f);
}
}
}//foreach end
//7:循环外删除目录!!
rmdir($path);
}
?>
php递归遍历出目录下的所有文件:
<?php
header('content-type:text/html;charset=gbk');
ini_set("date.timezone", "Asia/Chongqing");
/*
* 遍历一个指定目录()包括子目录和文件
* @param string $path 指定目录名称
* @return viod
*/
class dir{
function upl($path){
//判断处理的目录是否存在 不存在 return false;
if(!file_exists($path)){
return false;
}
//列出当前目录内容
$list=scandir($path);
foreach($list as $f){
//去除 . ..
if($f!='.'&&$f!='..'){
//判断是否是一个目录【$path.'/'.$f】
if(is_dir($path."/".$f)){
//输出
echo $path."/".$f."<br />";
//递归调用自己
$this->upl($path."/".$f);
}else{
//如果文件存在输出
echo $path."/".$f."<br />";
}
}//if end
}//foreach end
}
}
$a=new dir();
$a->upl("d:/www/guo/application");
最新评论
热门推荐
我要评论