<table cellspacing="0" cellpadding="0"><tr><td class="t_f" id="postmessage_65128"> <div class="blockcode"> <div id="code_uAu"><ol> <li> </li> <li><?<li>//代码也可以用于统计目录数<li>//格式化输出目录大小 单位:Bytes,KB,MB,GB<li> <li>function getDirectorySize($path)<li>{<li> $totalsize = 0;<li> $totalcount = 0;<li> $dircount = 0;<li> if ($handle = opendir ($path))<li> {<li> while (false !== ($file = readdir($handle)))<li> {<li> $nextpath = $path . '/' . $file;<li> if ($file != '.' && $file != '..' && !is_link ($nextpath))<li> {<li> if (is_dir ($nextpath))<li> {<li> $dircount ;<li> $result = getDirectorySize($nextpath);<li> $totalsize = $result['size'];<li> $totalcount = $result['count'];<li> $dircount = $result['dircount'];<li> }<li> elseif (is_file ($nextpath))<li> {<li> $totalsize = filesize ($nextpath);<li> $totalcount ;<li> }<li> }<li> }<li> }<li> closedir ($handle);<li> $total['size'] = $totalsize;<li> $total['count'] = $totalcount;<li> $total['dircount'] = $dircount;<li> return $total;<li>}<li> <li>function sizeFormat($size)<li>{<li> $sizeStr='';<li> if($size<1024)<li> {<li> return $size." bytes";<li> }<li> else if($size<(1024*1024))<li> {<li> $size=round($size/1024,1);<li> return $size." KB";<li> }<li> else if($size<(1024*1024*1024))<li> {<li> $size=round($size/(1024*1024),1);<li> return $size." MB";<li> }<li> else<li> {<li> $size=round($size/(1024*1024*1024),1);<li> return $size." GB";<li> }<li> <li>}<li> <li>$path="/home/www/htdocs";<li>$ar=getDirectorySize($path);<li> <li>echo "<h4>路径 : $path</h4>";</li> <li>echo "目录大小 : ".sizeFormat($ar['size'])."<br>";</li> <li>echo "文件数 : ".$ar['count']."<br>";</li> <li>echo "目录术 : ".$ar['dircount']."<br>";</li> <li> </li> <li>//print_r($ar);</li> <li>?></li> <li> </li> <li> </ol></div> <em onclick="copycode($('code_uAu'));">复制代码</em> </div> <br> </td></tr></table> <div class="ptg mbm mtn"> PHP</div> <div id="comment_65128" class="cm"> </div> <div id="post_rate_div_65128"></div> <br><br>