Copy CodeThe code is as follows:
/**
* Listdir
*/
Header ("Content-type:text/html;charset=utf-8");
$dirname = "./final/factapplication";
function Listdir ($dirname) {
$ds = Opendir ($dirname);
while (false!== ($file = Readdir ($ds))) {
$path = $dirname. ' /'. $file;
if ($file! = '. ' && $file! = ' ... ') {
if (Is_dir ($path)) {
Listdir ($path);
} else {
echo $file. "
";
}
}
}
Closedir ($DS);
}
Listdir ($dirname);
Core: Recursive classic applications, and basic operations for files and directories.
Copy the Code code as follows:
/**
* Copydir
*/
$srcdir = ". /fileupload ";
$dstdir = "B";
function Copydir ($srcdir, $dstdir) {
mkdir ($dstdir);
$ds = Opendir ($srcdir);
while (false!== ($file = Readdir ($ds))) {
$path = $srcdir. " /". $file;
$dstpath = $dstdir. " /". $file;
if ($file! = "." && $file! = "...") {
if (Is_dir ($path)) {
Copydir ($path, $dstpath);
} else {
Copy ($path, $dstpath);
}
}
}
Closedir ($DS);
}
Copydir ($srcdir, $dstdir);
Core: copy function.
Copy the Code code as follows:
/**
* Deldir
*/
$dirname = ' a ';
function Deldir ($dirname) {
$ds = Opendir ($dirname);
while (false!== ($file = Readdir ($ds))) {
$path = $dirname. ' /'. $file;
if ($file! = '. ' && $file! = ' ... ') {
if (Is_dir ($path)) {
Deldir ($path);
} else {
Unlink ($path);
}
}
}
Closedir ($DS);
return rmdir ($dirname);
}
Deldir ($dirname);
Core: Note that unlink deletes a file with path.
Copy the Code code as follows:
/**
* Dirsize
*/
$dirname = "a";
function Dirsize ($dirname) {
Static $tot;
$ds = Opendir ($dirname);
while (false!== ($file = Readdir ($ds))) {
$path = $dirname. ' /'. $file;
if ($file! = '. ' && $file! = ' ... ') {
if (Is_dir ($path)) {
Dirsize ($path);
} else {
$tot = $tot + filesize ($path);
}
}
}
return $tot;
Closedir ($DS);
}
echo dirsize ($dirname);
Core: The recursive function is understood by judging where $tot is returned.
http://www.bkjia.com/PHPjc/825270.html www.bkjia.com true http://www.bkjia.com/PHPjc/825270.html techarticle Copy the code as follows: PHP/** * listdir */Header ("Content-type:text/html;charset=utf-8"); $dirname = "./final/factapplication "; function Listdir ($dirname) {$ds = Opendir ($d ...