This article mainly talks about using PHP to traverse all directories and files in a directory, and delete the directory and all subdirectories and files under the directory. This code is implemented recursively. Interested Friends, let’s find out.
Functions used:
scandir($path) traverses all files in a directory and returns an array.
unlink($filename) Delete the file.
rmdir($path) only deletes empty folders.
PHP code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
Related tutorials:PHP video tutorial
The above is the detailed content of Use PHP to traverse and delete a directory and all files stored in this directory. For more information, please follow other related articles on the PHP Chinese website!