& 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
?>