Re: [LIP] is_dir function in php

Anil Menon <[email protected]>
Newsgroups gmane.user-groups.linux.india.programmers
Message-ID <[email protected]>
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);

?>

The just hacked it. |The original author is greez([email protected]) and 
hacked by |[email protected]
Original code at http://in2.php.net/dir

Anil Menon
MIS Team.

I'll try till I die or die trying. 



Logu wrote:

> Hi,
>
> I wrote a small php script to distiguish the files and sub-directories 
> of a directory. It lists the contents of the directory containing this 
> script file. But for other directories it is unable to distinguish the 
> diretory even though the directories has the apache user permission.
>
> For example in the below given script. If the $mydir value is assigned 
> with some other directory path other than the directory the script 
> contains, it is not properly recognising directories.
>
>
> Does anyone know how to overcome this.
>
> Thanks
> -logu
>
> #------------------------------------------------------------------
> <?php
>
> $mydir=".";
>
> if ($handle = opendir("$mydir")) {
>        while (false !== ($file = readdir($handle))) {
>                 if( is_dir("$file") == true )
>                         echo "$file is directory\n <br>";
>                 else
>                          echo "$file is file\n <br>";
>         }
> }
> ?>
>
> #------------------------------------------------------------------
>
>
>
> -------------------------------------------------------
> 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
> _______________________________________________
> linux-india-programmers mailing list
> linux-india-programmers-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> https://lists.sourceforge.net/lists/listinfo/linux-india-programmers



-------------------------------------------------------
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.