Return to Snippet

Revision: 33538
at October 9, 2010 21:47 by stz184


Initial Code
function my_delete($dir) {
	if(is_file($dir)) {
		if(!@unlink($dir)) {
			return false;
		}
		return true;
	}
	$hdl = opendir($dir);
	while($item = readdir($hdl)) {
		if($item != "." && $item != "..") {
			if(is_file($dir."/".$item)) {
				if(!@unlink($dir."/".$item)) {
					return false;
				}
			}
			else {
				my_delete($dir."/".$item);
			}
		}
	}
	closedir($hdl);
	if(@rmdir($dir)) {
		return true;
	}
	return false;
}

Initial URL

                                

Initial Description
This function can delete both non-empty directories and files.

Initial Title
Delete non-empty directory and files with one function

Initial Tags

                                

Initial Language
PHP