php 删除文件夹(可删除不是空的文件夹)
Jun 08, 2016 pm 05:26 PM这是一款删除文件夹的php函数,本函数用的是递归删除,他可以删除指定目录的所有文件夹与文件,可以删除不是空目录的文件夹,方便的很,下面来看看函数实例方法。
代码如下 | 复制代码 |
/*—————————————————— */ //– 递归删除文件及目录 //– 例: del_dir ('../www.1111cn.net/');注意:返回的/是必须的 //– $type 强制删除目录, true 是 ,false 否 /*—————————————————— */ function del_dir ($dir,$type=true) { $n=0; if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { //.svn 忽略 svn 版本控制信息 if ( $file == '.' or $file =='..' or $file == '.svn') { continue; } if (is_file ($dir.$file)) { unlink($dir.$file); $n++; } if (is_dir ($dir.$file)) { del_dir ($dir.$file.'/'); if ($type) { $n++; rmdir($dir.$file.'/'); } } } } closedir($dh); } return $n; } |
很容易看懂吧。原理很简单,首先是查询目录所有文件或目录,如果是文件就删除了,如果是目录看看是不是空目录,如果是的删除,否则再调用本函数一次类推,就实例了删除不是空目录的功能了。

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Hongmeng native application random poetry

How to write if in c language to judge multiple conditions

Use java's File.length() function to get the size of the file

Rename files using java's File.renameTo() function

Use java's File.getParentFile() function to get the parent directory of the file

Use java's File.getParent() function to get the parent path of the file

How to delete a file or directory using File.delete() method in Java?
