PHP recursively deletes all files in the directory:
<?php
Header ("Content-type:text/html;charset=utf-8");
/**
* Delete specified directory () Delete subdirectories and files
* @path file directory path string
* @return void
/function Hello ($path) {
// 1: Determine if the deletion directory exists if
(!file_exists ($path)) {return
false;
}
2: The contents of the catalog are all obtained
$list = Scandir ($path);
3: Traverse directory
foreach ($list as $f) {
//4: Will ... exclude outside
if ($f!= '. ' && $f!= ') {
//5: If the content file unlink if
(Is_file ($path.) /". $f)) {
unlink ($path.".). $f);
} else{
//6: Table of Contents recursive
Hello ($path.) /". $f);}}
foreach End
//7: Delete directory outside of loop!!
RmDir ($path);
>
PHP recursion facilitates all files in the directory:
<?php
Header (' CONTENT-TYPE:TEXT/HTML;CHARSET=GBK ');
Ini_set ("Date.timezone", "asia/chongqing");
* * Traverse a specified directory () including subdirectories and file
* @param string $path Specify directory name
* @return viod
/class dir{
function UPL ( $path) {
//To determine whether the directory being processed has no return false;
if (!file_exists ($path)) {return
false;
}
Lists the contents of the current directory
$list =scandir ($path);
foreach ($list as $f) {
//Remove ...
if ($f!= '. ') && $f!= ' ... ') {
//judge whether it is a directory "$path." /'. $f '
if (Is_dir ($path.) /". $f)) {//
output
echo $path." /". $f." <br /> ";
Recursively calls itself
$this->upl ($path. " /". $f);
} else{
//If file exists output
echo $path. " /". $f." <br /> ";
}
} If End
}//foreach end
}
}
$a =new dir ();
$a->upl ("d:/www/guo/application");