|
Posted by plato on 08/17/06 08:45
This is a homebrewed function I use to keep track of the size of my
code on certain projects. It takes two arguments: $dir is a string,
the path relative to the webserver of the directory you'd like to
parse, and $exclude is an array of top-level folders you don't want
searched. Because of the way PHP handles directory traversing (at
least on Windows boxes), the list comes back absolutely alphabetically
sorted, like this:
/a/b/c/d/e
/a/c/a/a/a
/b/a
function ls( $dir, $exclude ) {
static $i = 0;
$files = array();
$d = opendir( $dir );
while ($file = readdir($d))
{
if ($file == '.' || $file == '..') continue;
if (in_array($file, $exclude) ) continue;
if (is_dir( $dir.'\\'.$file ) and !in_array( $file, $exclude) ) {
$files += ls( $dir.'\\'.$file );
continue;
}
$files[ $dir."\\$file" ][ "lines" ] = count( file( $dir."\\$file" )
);
$files[ $dir."\\$file" ][ "size" ] = filesize( $dir."\\$file" );
$files[ $dir."\\$file" ][ "name" ] = $file;
$path = $dir."\\$file";
$path = str_replace( "\\", "/", $path );
$path = str_replace( $_SERVER['DOCUMENT_ROOT'], "", $path );
$files[ $dir."\\$file" ][ "path" ] = str_replace( "//", "/", $path );
}
return $files;
}
>From there, it wouldn't be too difficult to work up a solution to sort
by the filename provided by $ls_results[ $iterator ][ 'name' ].
[Back to original message]
|