*/
Delete File method in directory one
| The code is as follows |
Copy Code |
|
function Clean_dir ($path) {
if (!is_dir ($path)) {
if (Is_file ($path)) {
Unlink ($path);
}
Return
}
$p =opendir ($path);
while ($f =readdir ($p)) {
if ($f = = "." | | $f = = "...") Continue
Clean_dir ($path. $f);
}
RmDir ($path);
Return
}
//
function Delfile ($path, $level = 0) {
$path $file
Delete all file instances under directory two
$file = "";
$lev = 0;
$dir = @opendir ($path);
while ($con = @readdir ($dir)) {
if ($con!= "." && $con!= "..." && $con!= "") {
$file = $path. " /". $con;
if (Is_dir ($file)) {
$lev = Delfile ($file, $level + +);
@rmdir ($file);
} else {
@unlink ($file);
}
}
}
for ($i =0; $i < $lev; $i + +) {
Delfile ($path, $level);
}
@rmdir ($path);
return $level;
}
Delfile ("./www.111cn.net");
|
Directory traversal function
| The code is as follows |
Copy Code |
function DirTree ($path = "./test") {
echo "<dl>";
$d = Dir ($path);
while (false!== ($v = $d->read ())) {
if ($v = = "."
$v = = "...")
Continue
$file = $d->path. " /". $v;
echo "<dt> $v";
if (Is_dir ($file))
DirTree ($file);
}
$d->close ();
echo "</dl>";
} |
DirTree ();
//php file system functions are much better than ASP tutorials, delete directory All files as long as the unlink on the line, we just to the directory to traverse the is_file on the OK.
//This site to collate the reprint annotated www.111cn.net