-
- //Delete all files in the specified directory (folder) function
- function delfile($dir) {
- if (is_dir($dir)) {
- $dh=opendir($dir );//Open the directory
- //List all files in the directory and remove. and..
- while (false !== ( $file = readdir ($dh))) {
-
- if($file!=" ." && $file!="..") {
- $fullpath=$dir."/".$file;
- if(!is_dir($fullpath)) {
- unlink($fullpath);//Delete the directory All files
- } else {
- delfile($fullpath);
- }
- }
- closedir($dh);
- }
- }
- }
- //Delete the specified directory
- function deldir($dir) {
- delfile($ dir);
- if (is_dir($dir)) {
- rmdir($dir); //The directory must be empty
- }
- }
- ?>
Copy code
Guess you like:
Delete the php code of all files in the specified folder
Call example:
1. Delete all files in the "myphoto" folder in the D drive
-
- $dir="D:/myphoto";
- delfile($dir);
- ?>
Copy the code
2, delete "myphoto" in the D drive folder
-
- $dir="D:/myphoto";
- deldir($dir);
- ?>
Copy code
|