Home > Article > Backend Development > PHP directory operation example code_PHP tutorial
$dirname = "./final/factapplication";
function listdir($dirname) {
$ds = opendir($dirname);
while (false !== ($file = readdir($ds))) {
$path = $ dirname.'/'.$file;
if ($file != '.' && $file != '..') {
path);
} else {
}
closedir($ds);
}
listdir($dirname);
mkdir($dstdir);
$ds = opendir($srcdir);
while (false !== ($file = readdir($ds))) {
$path = $srcdir."/".$file;
$dstpath = $dstdir."/". $file;
if (is_dir($path)) {
copydir($path, $dstpath);
> closedir($ds);
}
copydir($srcdir, $dstdir);
Core: copy function.
The code is as follows:
$dirname = 'a';
function deldir($dirname) {
$ds = opendir($dirname);
while (false !== ($file = readdir($ds))) {
$path = $dirname.'/'.$file;
if($file != '.' && $file != '..') {
🎜>
Core: Note that unlink deletes the file with path.
Copy code
The code is as follows:
}
echo dirsize($dirname);
Core: Understand recursive functions by determining where $tot returns.
http://www.bkjia.com/PHPjc/825270.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/825270.html
Copy the code as follows: ?php /*** listdir*/ header("content-type:text/ html;charset=utf-8"); $dirname = "./final/factapplication"; function listdir($dirname) { $ds = opendir($d...