//循环删除目录和文件函数,不删除根目录
function delDirAndFile($dirName,$root)
{
if ( $handle = opendir( "$dirName" ) ) {
while ( false !== ( $item = readdir( $handle ) ) ) {
if ( $item != "." && $item != ".." ) {
if ( is_dir( "$dirName/$item" ) ) {
delDirAndFile( "$dirName/$item",$root);
} else {
if( unlink( "$dirName/$item" ) )echo "成功删除文件: $dirName/$item<br />\n";
}
}
}
closedir( $handle );
if($dirName!=$root){
if( rmdir( $dirName ) )echo "成功删除目录: $dirName<br />\n";
}
}
}
//删除文件
function delFileUnderDir( $dirName )
{
if ( $handle = opendir( "$dirName" ) ) {
while ( false !== ( $item = readdir( $handle ) ) ) {
if ( $item != "." && $item != ".." ) {
if ( is_dir( "$dirName/$item" ) ) {
delFileUnderDir( "$dirName/$item" );
} else {
if( unlink( "$dirName/$item" ) )echo "成功删除文件: $dirName/$item<br />\n";
}
}
}
closedir( $handle );
}
}
echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
$dir="/ADODB_cache";
delDirAndFile($dir,$dir);
//delFileUnderDir($dir);
function delDirAndFile($dirName,$root)
{
if ( $handle = opendir( "$dirName" ) ) {
while ( false !== ( $item = readdir( $handle ) ) ) {
if ( $item != "." && $item != ".." ) {
if ( is_dir( "$dirName/$item" ) ) {
delDirAndFile( "$dirName/$item",$root);
} else {
if( unlink( "$dirName/$item" ) )echo "成功删除文件: $dirName/$item<br />\n";
}
}
}
closedir( $handle );
if($dirName!=$root){
if( rmdir( $dirName ) )echo "成功删除目录: $dirName<br />\n";
}
}
}
//删除文件
function delFileUnderDir( $dirName )
{
if ( $handle = opendir( "$dirName" ) ) {
while ( false !== ( $item = readdir( $handle ) ) ) {
if ( $item != "." && $item != ".." ) {
if ( is_dir( "$dirName/$item" ) ) {
delFileUnderDir( "$dirName/$item" );
} else {
if( unlink( "$dirName/$item" ) )echo "成功删除文件: $dirName/$item<br />\n";
}
}
}
closedir( $handle );
}
}
echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
$dir="/ADODB_cache";
delDirAndFile($dir,$dir);
//delFileUnderDir($dir);