php traverses all files and folders in a folder, and removes all the files from all folders and subfolders, and achieves the effect of emptying a directory by recursion. The code is simple and practical.

is also suitable for cleaning cache in ThinkPHP. In ThinkPHP, you can write the following code into./Application/Admin/Common/function.php files, and then call this function to clean up the operation. The function

use:

scandir ($path) traverse a folder all the files and returns the array.
unlink ($filename) delete files.
rmdir ($path) only

 < to delete the empty folders; / / PHP? Set need to delete the folder $path = "./Application/Runtime/"; / / delete empty folder function empty folder function and empty the folder after the treatment of function deldir ($path) {/ / if a directory will continue to if (is_dir ($path)) {/ / scan all folders and files in a folder and returns an array of $p = scandir ($path); foreach ($p as $val) {/ / exclusion list. And.. if ($val! = & & "." $val! = "..") {/ / if the directory is recursive subdirectory, continue to operate if (is_dir ($path.$val)) {/ / sub directory operation to delete the folder and file deldir ($path.$val.'/'); / / delete empty empty ($path.$val.'/ directory folder @rmdir '); / / if}else{is to delete the unlink file directly ($path.$val);}}}}} / / call function, incoming path deldir ($path); 

"summarized above is Xiaobian to introduce the PHP method to delete a directory folder and all the file, I hope to help you, if you have any questions please give me a message, Xiao Bian will reply you timely. Thank you for your support for the home website of the script!

This paper fixed link:http://www.script-home.com/php-removes-all-folders-and-files-under-a-path.html | Script Home | +Copy Link

Article reprint please specify:PHP removes all folders and files under a path | Script Home

You may also be interested in these articles!