php 删除指定目录,并递归删除子目录的简单示例

前端之家收集整理的这篇文章主要介绍了php 删除指定目录,并递归删除子目录的简单示例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
PHP删除指定的目录,会递归删除子目录感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编两巴掌来看看吧!

/**
 * PHP删除指定的目录,会递归删除子目录
 *
 * @param 
 * @author 网: jb51.cc
 * Delete a file,or a folder and its contents (recursive algorithm)
 *
 * @version     1.0.3
 * @param       string   $dirname    Directory to delete
 * @return      bool     Returns TRUE on success,FALSE on failure
 */
function rmdirr($dirname)
{
	// Sanity check
	if (!file_exists($dirname)) {
		return false;
	}
	// Simple delete for a file
	if (is_file($dirname) || is_link($dirname)) {
		return unlink($dirname);
	}
	// Loop through the folder
	$dir = dir($dirname);
	while (false !== $entry = $dir->read()) {
		// Skip pointers
		if ($entry == '.' || $entry == '..') {
			continue;
		}
		// Recurse
		rmdirr($dirname . DIRECTORY_SEPARATOR . $entry);
	}
	// Clean up
	$dir->close();
	return rmdir($dirname);
}

/***   来自编程之家 jb51.cc(jb51.cc)   ***/

猜你在找的PHP相关文章