note 36405 added to ref.dir
| From: | arun at upress dot unm dot edu | Date: | Wed, 08 Oct 2003 19:34:02 +0000 |
| Subject: | note 36405 added to ref.dir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-58069@lists.php.net to get a copy of this message | ||
correction to piccaso at gmx dot net's
function recrusive_dirlist($base_dir)
<?
/*
This function retuns all directory and file names from the given directory.
Works recrusive. Based on ltena at gmx dot net's function.
*/
function recrusive_dirlist($base_dir)
{
global $getDirList_alldirs,$getDirList_allfiles;
function getDirList($base)
{
global $getDirList_alldirs,$getDirList_allfiles;
if(is_dir($base))
{
$dh = opendir($base);
while (false !== ($dir = readdir($dh)))
{
if (is_dir($base ."/". $dir) && $dir !== '.' && $dir
!== '..') //note the change in this line
{
$subs = $dir ;
$subbase = $base ."/". $dir;//note the change in this line
$getDirList_alldirs[]=$subbase;
getDirList($subbase);
}
elseif(is_file($base ."/". $dir) && $dir !== '.' &&
$dir !== '..')//change in this line too
{
$getDirList_allfiles[]=$base ."/". $dir;//change in this line too
}
}
closedir($dh);
}
}
getDirList($base_dir);
$retval['dirs']=$getDirList_alldirs;
$retval['files']=$getDirList_allfiles;
return $retval;
}
// example usage:
echo '<pre>';
print_r(recrusive_dirlist('/home/computerdreams.at/cms/'));
echo '</pre>';
/*
Prints out something like this:
Array
(
[dirs] => Array
(
[0] => /home/computerdreams.at/cms/xoops-2.0.3/
[1] => /home/computerdreams.at/cms/xoops-2.0.3/html/
[2] => /home/computerdreams.at/cms/xoops-2.0.3/html/modules/
[3] => /home/computerdreams.at/cms/xoops-2.0.3/html/modules/news/
...
...
)
[files] => Array
(
[0] => /home/computerdreams.at/cms/li
[1] => /home/computerdreams.at/cms/lo
[2] => /home/computerdreams.at/cms/tab
[3] => /home/computerdreams.at/cms/tmp
...
...
)
)
I downt know if this is the best way to do this.
If you find a better way, please drop me a note.
greez
piccaso@gmx.net
*/
?>
I used the function without making any changes and did not get any output, no error though. then i
realised the mistake and did the changes and got perfect output.
hope this helps someone in future.
Arun.
----
Manual Page -- http://www.php.net/manual/en/ref.dir.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+36405
Delete -- http://master.php.net/manage/user-notes.php?action=delete+36405&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+36405&report=yes
Search -- http://master.php.net/manage/user-notes.php