Home>Article>Backend Development> How to delete directories recursively in php

How to delete directories recursively in php

王林
王林 Original
2020-11-05 11:35:08 2369browse

php method to recursively delete a directory: first use the opendir function to open the directory handle; then read the entry from the directory handle, and use the readdir function to return the file name of the next file in the directory; finally delete the directory in sequence, and Just close the directory handle.

How to delete directories recursively in php

Related functions:

opendir() function opens a directory handle. If successful, the function returns a directory stream, otherwise it returns false and an error.

(Related learning video recommendations:java video tutorial)

closedir() function closes the directory handle.

readdir() function returns the file name of the next file in the directory.

Code sample:


      

Related recommendations:php training

The above is the detailed content of How to delete directories recursively in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn