PHP Delete Non-empty Directory program code _php tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.