PHP clears (deletes) the file under the specified directory, does not delete the Directory folder implementation code,
In web development, we may encounter the need to empty all files in a directory, but not delete subdirectories in this directory (and certainly not delete the deleted root directory). So how do you deal with this method of deleting a file without deleting the directory? The following bloggers will share with you a better solution to this problem. Look at the following function:
/* Delete the files under the specified directory, do not delete the directory folder */function delfile ($dirName) {if (file_exists ($dirName) && $handle =opendir ($dirName)) { while (false!== ($item = Readdir ($handle))) {if ($item! = "." && $item! = "...") {if (file_exists ($dirName. ') /'. $item) && Is_dir ($dirName. ' /'. $item)} {delfile ($dirName. ') /'. $item);} Else{if (Unlink ($dirName. ' /'. $item)) {return true;}}} Closedir ($handle);}}
http://www.bkjia.com/PHPjc/874632.html www.bkjia.com true http://www.bkjia.com/PHPjc/874632.html techarticle php Empty (delete) the file under the specified directory, do not delete the Directory folder implementation code, Web development we may encounter the need to be a directory of all files emptied, but not deleted ...