shell commands + listing function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Wishes.

I am not comfortable with shell scripting though know a bit here and
there. I believe the listing of a directory using php logic alone
would not give appreciable performance if i have lots of nested
directories.

I really believe a shell commands would solve this and would be short
and sweet also. I request help to convert the below to make use of
shell commands


function filesNameFromDirectory( $path = '.', $level = 0 )

    {

        $filenames = '';

        $ignore = array( 'cgi-bin', '.', '..' );

        $dh = @opendir( $path );

        while( false !== ( $file = readdir( $dh ) ) )

        {

            if( !in_array( $file, $ignore ) )

            {    

                $spaces = str_repeat( ' ', ( $level * 4 ) ); 

                if( is_dir( "$path/$file" ) )

                {

                    $this->filesNameFromDirectory( "$path/$file",
($level+1) );                      

                } else 

                {

                    if($filenames == '')

                    {

                          $filenames = substr($file,0,-4);

                    }

                    else

                    {

                          $filenames .= ','.substr($file,0,-4);

                    }

                }

            }    

        }

        closedir( $dh );

        return $filenames;

    } 




With regards

Harish


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux