| | |
request help :listing directories with php >> changing to use shell commands: how to?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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
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
Re: request help :listing directories with php >> changing to use shell commands: how to?
0
#2 Mar 4th, 2007
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.
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!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
![]() |
Similar Threads
- PHP Ajax Search (PHP)
- shell commands in python (Python)
- Need help uncompressing tar.gz file (Shell Scripting)
- How to execute shell command form Java servlet? (Java)
- Running PHP scripts in backround (PHP)
- Linux shell commands on Windows (IT Professionals' Lounge)
- PHP Forums Warning: New Strain Santy Worm Attacks (PHP)
Other Threads in the PHP Forum
- Previous Thread: dynamic dropdowm list and mysql
- Next Thread: hi
Views: 1311 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic ebooks echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla jquery js limit link login loop mail mediawiki menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select server sessions sms soap source space speed sql stored structure subdomain syntax system table tutorial update updates upload url validation validator variable video web xml youtube






