Home >php教程 >php手册 >php unlink与rmdir实现文件与文件夹删除

php unlink与rmdir实现文件与文件夹删除

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-25 16:56:451115browse

php教程 unlink与rmdir实现文件与文件夹删除

删除目录及文件
<?php 
function delsvn($dir) { 
$dh=opendir($dir); 
//找出所有".svn" 的文件夹: 
while ($file=readdir($dh)) { 
if($file!="." && $file!="..") { 
$fullpath=$dir."/".$file; 
if(is_dir($fullpath)) { 
if($file==".svn"){ 
delsvndir($fullpath); 
}else{ 
delsvn($fullpath); 
} 
} 
} 
} 
closedir($dh); 
} 
function delsvndir($svndir){ 
//先删除目录下的文件: 
$dh=opendir($svndir); 
while($file=readdir($dh)){ 
if($file!="."&&$file!=".."){ 
$fullpath=$svndir."/".$file; 
if(is_dir($fullpath)){ 
delsvndir($fullpath); 
}else{ 
unlink($fullpath); 
} 
} 
} 
closedir($dh); 
//删除目录文件夹 
if(rmdir($svndir)){ 
return true; 
}else{ 
return false; 
} 
} 
$dir=dirname(__FILE__); 
//echo $dir; 
delsvn($dir); 

删除目录
<? 
function deldir($dir) { 
//先删除目录下的文件: 
$dh=opendir($dir); 
while ($file=readdir($dh)) { 
if($file!="." && $file!="..") { 
$fullpath=$dir."/".$file; 
if(!is_dir($fullpath)) { 
unlink($fullpath); 
} else { 
deldir($fullpath); 
} 
} 
} 
closedir($dh); 
//删除当前文件夹: 
if(rmdir($dir)) { 
return true; 
} else { 
return false; 
} 
} 

本文地址:

转载随意,但请附上文章地址:-)

Statement:
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