Non-empty directory refers to the directory there are other files or folders, the deletion principle is: First we enter the directory to find out whether it is an empty directory or file to delete, if not into the subordinate directory until the empty directory and then return to delete the ancestor, that is, to traverse the directory to delete.
is a super-simple PHP tutorial, but also into the entry-level things, not much to say
Code
|
copy code |
!--? php //Description: Delete solution for non-empty directory Func tion RemoveDir ($dirName) { if (! Is_dir ($dirName)) { return false; } $handle = @opendir ($dirName); while (($file = @readdir ($handle))!== false) { if ($file! = '. ' && $file! = ') { $dir = $dirName. '/' . $file; Is_dir ($dir)? RemoveDir ($dir): @unlink ($dir); } } Closedir ($handle); Return rmdir ($dirName); } ? |
There are a lot of methods, here is not introduced, in fact, the program unlink delete files, and rmdir delete this directory.
http://www.bkjia.com/PHPjc/628900.html www.bkjia.com true http://www.bkjia.com/PHPjc/628900.html techarticle non-empty directory refers to the directory there are other files or folders, the deletion principle is: first we go into the directory to find out whether it is an empty directory or file to delete, if not re-enter the subordinate ...