php
/**
* 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);
核心:递归的经典应用,以及文件和目录的基本操作。
/**
* 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);
超级适合代理建设企业站点的企业源码,超方面实用!程序说明: 1.特色:简繁中文切换、产品展示系统、新闻发布系统、会员管理系统、留言本计数器、网站信息统计、强大后台操作 功能等; 2.页面包括:首页、企业介绍、滚动公告通知发布系统、企业新闻系统、产品展示系统、企业案例发布展示系 统、企业招聘信息发布系统、信息资源下载系统、在线定单系统、在线客服系统、在线留言本系统、网站调查投票系统、友情连接系统、会
核心:copy函数。
/**
* 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);
核心:注意unlink删除的是带path的file。
/**
* 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);
核心:通过判断$tot在哪里返回,理解递归函数。










