PHP 删除文件与文件夹操作 unlink()与rmdir()这两个函数的使用
来源:互联网 发布:淘宝装修主页 编辑:程序博客网 时间:2024/06/03 01:19
先看一下代码
<?
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;
}
}
?>
unlink() 函数用于删除文件。若成功,则返回 true,失败则返回 false。rmdir() 函数用于删除空的目录。它尝试删除 dir 所指定的目录。 该目录必须是空的,而且要有相应的权限。
一个实例:删除某个文件夹下的所有".svn"文件夹(包括其内容也要被删除)。
<?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;
}
}
?>
unlink() 函数用于删除文件。若成功,则返回 true,失败则返回 false。rmdir() 函数用于删除空的目录。它尝试删除 dir 所指定的目录。 该目录必须是空的,而且要有相应的权限。
一个实例:删除某个文件夹下的所有".svn"文件夹(包括其内容也要被删除)。
复制代码代码如下:
<?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);
?>
0 0
- PHP 删除文件与文件夹操作 unlink()与rmdir()这两个函数的使用
- php中的unlink(),unset(),rmdir()删除函数
- php的unlink()函数删除上级目录文件
- Linux中对文件删除函数unlink的操作
- Linux中对文件删除函数unlink的操作
- php文件删除,unlink()
- php删除文件与文件夹
- PHP unlink删除本地中文名称的文件
- 4.20 mkdir和rmdir函数-目录的创建与删除
- php文件删除unlink()详解
- php文件删除unlink()详解
- php文件删除unlink()详解
- JAVA操作文件或文件夹的创建与删除
- 系统函数-文件操作-unlink()
- php rmdir使用递归函数删除非空目录
- php rmdir使用递归函数删除非空目录
- php今天碰到unlink不能删除文件的问题
- 文件与目录操作--link、unlink、remove和rename函数 及 文件与目录--utime函数
- 浅析Java中的final关键字
- web项目部署到服务器流程
- the project description file (.project) is out of sync with the file system.
- 深入理解JavaScript系列(三): 作用域链与闭包
- Ubuntu15.10配置redmine
- PHP 删除文件与文件夹操作 unlink()与rmdir()这两个函数的使用
- Oracle scott账户被锁定,scott默认密码,sys,system默认密码
- 正则表达式及java相关练习
- centos本地yum源错误引起问题
- 【设计模式】Java服务开发应用策略模式的一个例子
- 分析MockHttpServletRequestBuilder中content和param的区别
- 为or、in平反——or、in到底能不能利用索引?
- SQL 递归生成树
- mac下vim配置