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

Hi,

Any help or pointers please. I am really stuck with here.The application works fine but i am reviewing and thought of gettting the shell commands for better performance.

Regards.

The exec() function may help you.

http://php.net/function.exec

It allows you to execute shell commands from PHP.

You could for example exec to execute "ls" or "dir" and then parse the return for the directories.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.