phpbar.de logo

Mailinglisten-Archive

[php] Rekursives Directory Listing

[php] Rekursives Directory Listing

Thomas Feyrer Dante_(at)_altmuehlnet.de
Wed, 28 Jul 1999 13:49:22 +0200


--=====================_933155362==_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

At 11:24 28.07.99 GMT, Andreas Kraftl wrote:
>meine kleinen Kenntnisse reichen nicht aus, um folgende Vorstellung zu=20
>realisieren.
>
>Ein Script welches von einem Verzeichnis startend alle *.htm, *.html,=20
>*.shtml, *.php3 und *.phps Dateien in ein Textfile schreibt. Wie im=20
>Topic erw=E4hnt sollen auch Unterordner bearbeitet werden.
>
>Die Ausgabe sollte so aussehen:
>
>/dir1/dir2/bla.html
>/dir1/bla.shtml

Hi Andreas,
ich hab hier mal ein Skript von mir angeh=E4ngt...
es macht noch mehr als du eigentlich willst...=20
wenn du in der Zeile mit:
// echo( $entry );
die "//" entfernst, werden auch die Verzeichnisse mit ausgegeben, und ganz
oben musst du nur noch die fehlenden typen mit angeben...

Bye
 Dante
--=====================_933155362==_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename="source-counter2.php3"

<?

/*
|---------------------------------------------------------------------------=
-|
| Source Counter v0.2.1                                                     =
 |
|---------------------------------------------------------------------------=
-|
| Author/Autor:                                                             =
 |
|   Thomas Feyrer                                                           =
 |
|   Dante_(at)_altmuehlnet.de                                                    =
 |
|---------------------------------------------------------------------------=
-|
| Englisch:                                                                 =
 |
|   Counts  the number of files  in the  current directory and  in its  sub-=
 |
| directorys, you can define the endings of the files self.                 =
 |
|   Further it counts the size and the number of lines of these files.      =
 |
|                                                                           =
 |
|   Thanks  for using this script.  This script can and should be  modified.=
 |
| Please send possible changes to me.                                       =
 |
|---------------------------------------------------------------------------=
-|
| Deutsch (German):                                                         =
 |
|   Z=E4hlt  die Anzahl der  Dateien im aktuellen und in =
 Unterverzeichnissen, |
| deren  Endung beliebig sein kann.                                         =
 |
|   Weiterhin addiert es die Gr=F6=DFen und Zeilenanzahl dieser Dateien.    =
     |
|                                                                           =
 |
|   Danke f=FCr die Benutzung dieses Skripts.  Dieses Skript darf und soll=
 mo- |
| difiziert werden, bitte schicken sie eventuelle Ver=E4nderungen an mich.  =
   |
|---------------------------------------------------------------------------=
-|
| Copyright 1999 by Thomas Feyrer                                           =
 |
|---------------------------------------------------------------------------=
-|
*/

set_time_limit( 0 );

$start_time =3D explode( " ", microtime() );

$directory =3D "/usr/local/httpd/htdocs";
$system =3D 1;	// 1 on UN*X-Systems, 0 on Windows-Systems !
$explore_subdirs =3D 1;
$file =3D array(
    "php3" =3D> array( "type" =3D> 1, "number" =3D> 0, "size" =3D> 0,=
 "lines" =3D> 0 ),
    "php"  =3D> array( "type" =3D> 1, "number" =3D> 0, "size" =3D> 0,=
 "lines" =3D> 0 ),
    "inc"  =3D> array( "type" =3D> 1, "number" =3D> 0, "size" =3D> 0,=
 "lines" =3D> 0 ),
    "html" =3D> array( "type" =3D> 1, "number" =3D> 0, "size" =3D> 0,=
 "lines" =3D> 0 ),
    "htm"  =3D> array( "type" =3D> 1, "number" =3D> 0, "size" =3D> 0,=
 "lines" =3D> 0 ),
    "gif"  =3D> array( "type" =3D> 0, "number" =3D> 0, "size" =3D> 0 ),
    "jpg"  =3D> array( "type" =3D> 0, "number" =3D> 0, "size" =3D> 0 )
);		// "type" =3D> 1 just on text-files, "type" =3D> 0 on binarays !

$files =3D 0;
$directorys =3D 0;
$unknowntype[number] =3D 0;
$links[number] =3D 0;

function dir_explore( $directory ) {
    global $files, $file, $directorys, $unknowntype, $links,=
 $explore_subdirs, $system;
    $dir =3D dir( $directory );
    while( $entry =3D $dir->read() ) {
        if( $entry =3D=3D "." || $entry =3D=3D ".." ) continue;
        $entry =3D $directory.$entry;
        if( is_dir( $entry ) && $explore_subdirs ) {
            $directorys++;
            if( $system ) {
                dir_explore( $entry."/" );
            } else {
                dir_explore( $entry."\\" );
            }
        }
        if( is_file( $entry ) ) {
            $files++;
            for( reset( $file ); $key =3D key( $file ); next( $file ) )
// echo( $entry );
                if( eregi( ".*\.$key$", $entry ) ) {
                    $file[$key][number]++;
                    $file[$key][size] +=3D filesize( $entry );
                    if( $file[$key][type] ) $file[$key][lines] +=3D sizeof(=
 file( $entry ) )+1;
                }
        } elseif( is_link( $entry ) ) {
            $links[number]++;
        } elseif( !is_dir( $entry ) ) {
            $unknowntype[number]++;
        }
    }
}

function explore( $directory ) {
    if( $system ) {
        if( !ereg( ".*/$", $directory ) ) $directory .=3D "/";
    } else {
        if( !ereg( ".*\\$", $directory ) ) $directory .=3D "\\";
    }
    dir_explore( $directory );
}

explore( $directory );

echo( "Files complete: $files\n" );
echo( "Directorys complete: $directorys\n" );
echo( "Links complete: $links[number]\n" );
echo( "Unknowns complete: $unknowntype[number]\n" );
for( reset( $file ); $key =3D key( $file ); next( $file ) ) {
    echo( "*.$key\n - Number: ".$file[$key][number]."\n - Size:=
 ".$file[$key][size]."\n" );
    if( $file[$key][type] ) echo(  " - Lines: ".$file[$key][lines]."\n" );
}

$stop_time =3D explode( " ", microtime() );

$start_time =3D $start_time[0] + $start_time[1] * 1000;
$stop_time =3D $stop_time[0] + $stop_time[1] * 1000;
$time =3D $stop_time - $start_time;
echo( "\nNeeded Time: $time seconds\n" );

?>
--=====================_933155362==_
Content-Type: text/plain; charset="us-ascii"



--=====================_933155362==_--



php::bar PHP Wiki   -   Listenarchive