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

Reply

Join Date: Apr 2005
Posts: 183
Reputation: hbmarar is an unknown quantity at this point 
Solved Threads: 0
hbmarar's Avatar
hbmarar hbmarar is offline Offline
Junior Poster

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

 
0
  #1
Mar 3rd, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 183
Reputation: hbmarar is an unknown quantity at this point 
Solved Threads: 0
hbmarar's Avatar
hbmarar hbmarar is offline Offline
Junior Poster

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

 
0
  #2
Mar 4th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,085
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

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

 
0
  #3
Mar 4th, 2007
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.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1311 | Replies: 2
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC