PHP
·
发表于 5年以前
·
阅读量:8303
<?
//ÒÔÊ÷Ðͽa¹¹ÁгoÖ¸¶¨Ä¿Â¼ÀiµÄËuÓÐÎļþ£¬Èç¹uÄaÏeÖªµÀ×Ô¼ºÄ³¸oĿ¼ÀiÓÐÄÄÐ(C)×ÓĿ¼ºÍÎļþ£¬¿ÉÒÔµ÷ÓÃÕa¸oÀaÀ´²e¿´£¬ºÜ*½±aµÄ¡£
# ÑÝʾµÄÀý×Ó:
$t = new TreeClimber( "asp" ); //н¨Îi¼þ,ÉeÖÃÐeÒªÁгoµÄĿ¼:ÔÚ´ËΪaspĿ¼
echo arrayValuesToString( $t->getFileList( $t->getPath() ), "<BR>\n" );
function arrayValuesToString( $ar, $nl="", $dolast=true ) {//µ÷Óú¯Êý
$str = "";
reset( $ar );
$size = sizeof( $ar );
$i = 1;
while( list( $k, $v ) = each( $ar ) ) {
if ( $dolast == false ) {
if ( $i < $size ) {
$str .= $ar[$k].$nl;
}
else {
$str .= $ar[$k];
}
}
else {
$str .= $ar[$k].$nl;
}
$i++;
}
return $str;
}
?>
<?
//ÒÔÏÂΪÀaÎļþ
class TreeClimber {
var $path;
var $fileList = array();
function TreeClimber( $path = "." ) {
$this->path = $path;
}
# ´aeÈ¡Â*¾¶
function getPath() { return $this->path; }
function setPath( $v ) { $this->path = $v; }
// *µ»ØÖ¸¶¨Ä¿Â¼ÀiµÄÎļþÁбi£¬Èç¹uûÓÐÖ¸¶¨Ä¿Â¼£¬½«Ê¹Óõ±Ç°Ä¿Â¼
//Èç¹u²»ÄÜ´o¿ªÄ¿Â¼£¨¿ÉÄÜûȨÏÞ»oĿ¼²»´aeÔÚ£¬½«*µ»ØΪ¿Õ
//ÒԵݹe*½Ê½½øÐÐ
function getFileList( $dirname=null, $returnDirs=false, $reset=true ) {
if ( $dirname == null ) { $dirname = $this->path; }
# else { $this->setPath( $dirname ); }
# dout( "Recursing into $dirname..." );
if ( $reset ) {
$this->fileList = array();
}
$dir = opendir( $dirname );
if ( ! $dir ) {
print( "<B><FONT COLOR=#FF0000>×¢Òa: TreeClimber.getFileList( $dirname ): ²»ÄÜ´o¿ª $dirname!</FONT></B>" );
return null;
}
while( $file = readdir( $dir ) ) {
if ( ereg( "^\\.$", $file ) || ereg( "^\\.\\.$", $file ) ) continue;
if ( is_dir( $dirname."/".$file ) ) {
$this->getFileList( $dirname."/".$file, $returnDirs, false );
if ( $returnDirs ) { $this->fileList[] = $dirname."/".$file;}
}
else { $this->fileList[] = $dirname."/".$file; }
}
sort( $this->fileList );
return $this->fileList;
}
} //ÖÁ´ËÀa½aÊø
?>