Re: [LIP] is_dir function in php
"Logu" <[email protected]>
| Newsgroups | gmane.user-groups.linux.india.programmers |
|---|---|
| Message-ID | <033f01c4f8be$394340c0$140110ac@loguco> |
> Hi Logu,
>
> try this code. This will list down all the directories and files under a
> path.
>
> <?
> 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 !==
> '..') {
> $subs = $dir ;
> $subbase = $base ."/". $dir;
> echo "$subbase is Directory <br><br>"; // Prints
> directories here
> getDirList($subbase);
> } elseif(is_file($base ."/". $dir) && $dir !== '.' && $dir
> !== '..') {
> $file = $base ."/". $dir;
> echo "$file is file <br>"; // prints files here
> }
> }
> closedir($dh);
> }
> }
>
> getDirList($base_dir);
> return $retval;
> }
>
> $myPath = '.'
> recrusive_dirlist($myPath);
>
> ?>
thanks for this code.
But I would like to know what is wrong with the code that I wrote. Why
is_dir() function is not working correctly. Or am I doing something wrong.
-logu
-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt