The fun of file processing is amazing.

Source: Internet
Author: User
& Lt ;? Php/* today, I attended the course to process this file. In the future, it is estimated that many directories need to be created using php during project creation. There may be multiple directories under one directory, it may also be a directory nested directory. If you create a directory, you must delete it. Today we are going to learn about the built-in functions of the php system... syntaxHighlighter. all ();

/* Today I attended the course to process this file. In the future, it is estimated that many directories need to be created using php during project creation. There may be multiple directories under one directory, it may also be a directory nested directory. If you create a directory, you must delete it. Today, we learn that the built-in functions of the php system contain the function for deleting the directory, for example, rmdir (), the syntax prototype of this function is bool rmdir (string $ dirname). It tries to delete the directory specified by dirname. The directory must be empty and have the corresponding permissions. TRUE is returned when the operation succeeds, or FALSE is returned when the operation fails, that is, the directory specified by dir is deleted. However, the dir directory must be empty. Note that it must be empty. This is a problem. When there is content in the directory or there is a directory in the directory, when we confirm that this directory and all files and directories under this directory do not have any meaning, what should we do to delete this directory? The simple rmdir () function cannot meet our needs, so we need to use other functions to help us. The following function will directly Delete the directory you need to delete, files or multi-level directories can be killed. let's take a look at the Code */
// You need to develop the habit of writing comments.
Function rm_dir ($ wenjian) {// Delete the directory function name when writing a UDF name.
$ D = dir ($ wenjian); // Its syntax is Directory dir (string $ directory [, resource $ context])
While (false! ==( $ Child = $ d-> read () {// This code is the key part. You can delete all the files in it.
If ($ child! = '.' & $ Child! = '..') {// Starts to judge!
If (is_dir ($ wenjian. '/'. $ child )){
Rm_dir ($ wenjian. '/'. $ child );
} Else {
Unlink ($ wenjian. '/'. $ child );
} // Judge the end!
}
}
$ D-> close ();
Rm_dir ($ wenjian); // clear the Directory
?>

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.