This article mainly introduced the PHP traversal deletes the entire directory and the file method, involves the PHP operation directory and the file skill, has certain reference value, needs the friend to be possible to refer to under
This article illustrates the way PHP traverses the entire directory and files. Share to everyone for your reference. The specific analysis is as follows:
We can delete directories and subdirectories and files using Recursivedirectoryiterator and Recursiveiteratoriterator, and subdirectories will be deleted first with the parent directory
?
1 2 3 4, 5 6 7 8 9 10 11 12 13 14 15 |
<?php function Cleanup_directory ($dir) {$iter = new recursivedirectoryiterator ($dir); foreach (new Recursiveiteratoriterator ($iter, Recursiveiteratoriterator::child_first) as $f) {if ($f->isdir ()) {rmdir ($f-> GetPathName ()); else {unlink ($f->getpathname ());}} RmDir ($dir); } cleanup_directory (' C:wampjunk ');?> |
I hope this article will help you with your PHP program design.