954,591 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

request help :listing directories with php >> changing to use shell commands: how to?

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

[PHP]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;
}[/PHP]

With regards

Harish

hbmarar
Junior Poster
190 posts since Apr 2005
Reputation Points: 10
Solved Threads: 0
 

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.

hbmarar
Junior Poster
190 posts since Apr 2005
Reputation Points: 10
Solved Threads: 0
 

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.

digital-ether
Nearly a Posting Virtuoso
Moderator
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You