Excerpt from "Linuxer" blog
http://deidara.blog.51cto.com/400447/118805
To delete an empty directory is simple ~ a
RmDir () function can be done, but to delete a non-empty directory, you will not be able to quickly delete, you must first delete the directory files, but there may be subdirectories in the directory so to be recursive delete ~ here is my example ~
function Deletedir ($dir) {
if (!handle= @opendir ($dir)) {//detects if the directory to open exists
Die ("No such directory");
}
while (False!== ($file =readdir ($handle))) {
if ($file!== "." && $file!== "..") {//Exclude current directory from parent directory
$file = $dir. Directory_separator. $file;
if (Is_dir ($file)) {
Deletedir ($file);
}else{
if (@unlink ($file)) {
echo "File $file deleted successfully.
";
}else{
echo "File $file Delete failed!
";
}
}
}
if (@rmdir ($dir)) {
echo "Directory $dir deleted successfully.
";
}else{
echo "Directory $dir Delete failed!
";
}
}
Test program
$dir = "/var/www/test";
Deletedir ($dir);
?>
Create a Write folder and file test under the/var/www/test folder
Shell> Touch AAA
Shell> Touch BBB
Shell> Touch CCC
Shell> Touch eee
Shell> Touch FFFF
Shell> mkdir 111
shell> mkdir 222
shell> mkdir 333
Write files in the 111,222,333 folder, respectively. There's not much to say, and then give them permission.
Shell>chown [Url]www.www[/url] Test-r
Then open the program in IE test it ~ hehe.
http://www.bkjia.com/PHPjc/508519.html www.bkjia.com true http://www.bkjia.com/PHPjc/508519.html techarticle excerpt from "linuxer" blog http://deidara.blog.51cto.com/400447/118805 to delete an empty directory is very simple ~ a rmdir () function can be done, but to delete a non-empty directory, ...