944,122 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1513
  • PHP RSS
Mar 3rd, 2007
0

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

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster
hbmarar is offline Offline
187 posts
since Apr 2005
Mar 4th, 2007
0

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

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.
Reputation Points: 10
Solved Threads: 0
Junior Poster
hbmarar is offline Offline
187 posts
since Apr 2005
Mar 4th, 2007
0

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

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.
Moderator
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
digital-ether is offline Offline
1,250 posts
since Sep 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: dynamic dropdowm list and mysql
Next Thread in PHP Forum Timeline: hi





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC