Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

not listing dirs

Status
Not open for further replies.

801119

Programmer
Joined
Apr 10, 2000
Messages
311
Location
SE
I'm using following code(see bottom) to list directories on my 'puter, but it refuses to print out some of the direcotires, which are only shown when removing "is_dir($path."/".$file)".
Anyone know of this problem? The folders that are not show has proper names, short names too. In one folder the subdirs where shown untill I renamned them (from "dune - forever" to just "forever"). I'm using XP and apache 2.0.46 (i think it was) so could it have anything to do with that?

Code:
function listdir($path)
{
    $aDir = array();
    if ($handle = opendir($path))
    {
        while (false !== ($file = readdir($handle)) && is_dir($path."/".$file))
        {
            if( $file !== "." && $file !== ".." )
                $aDir[count($aDir)] = $file;
        }
    }
    return $aDir;
}

My codes look like something a kid wrote
I have absolutely no idea what I am talking about
Somehow I still manage to make it work
 
No, I've checked the permissions.. and they all have the same!!

My codes look like something a kid wrote
I have absolutely no idea what I am talking about
Somehow I still manage to make it work
 
when I changed this part it worked.. wonder why!!
Code:
while (false !== ($file = readdir($handle)) && is_dir($path."/".$file))
{
    if( $file !== "." && $file !== ".." )
New code
Code:
while (false !== ($file = readdir($handle)))
{
    if( is_dir($path."/".$file) && $file !== "." && $file !== ".." )

My codes look like something a kid wrote
I have absolutely no idea what I am talking about
Somehow I still manage to make it work
 
try this:
while((false !== ($file = readdir($handle))) && (is_dir($path."/".$file)))
{
if( ($file !== ".") && ($file !== "..") )

there are sometimes some problems with brackets due to operator priority. I allways put anything into the brackets in conditions just to be sure...
 
Oh, I forgot one thing, use:
Code:
if(($file != ".")&&($file != ".."))
instead of the !== operator (this have little different meaning than nonequivalence !=)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top