Page 1 of 1

Finding only directries?

Posted: Mon Aug 17, 2009 10:56 am
by Monotoko
Hiya guys, was wondering if you could help me with a lil scripting problem....time is money and im completly stuck :/
My boss needs this code doing for tonight....so i dont have long.

Basically, this little script should go to the root of the server, and find all the directries, the only problem is, it isnt giving my the directries!
in the root folder i have:

dir:hello1
dir:hello2
dir:hello3
file: helloworld.txt

What i need the code to do is read that, and choose the directries, which it should do.

But when i echo back the $temp variable, it gives me no luck, only: .. and .
so how do i make the code read only the directries, then go through each one?

Below is the snippet of code

Code: Select all

//Open the logfile and input the server IP
$ip_hold = $_SERVER['SERVER_ADDR'];
$ip_write = "The IP of the server that send this log is".$ip_hold."";
$fh = fopen($PUBSTER_EMAIL.".txt", "w");
fwrite($fh,$ip_write);
//Open www directory
$dir = opendir("../../");
$count = 0;
$count2 = 0;
//Put all files into an array
while (($file = readdir($dir)) !== false)
  {
$files[$count]=$file;
$count++;
  }
closedir($dir);
 
while ($count2 != $count)
{
$temp = $files[$count2];
$direc = "../$temp";
if(is_dir($direc))
    {
        $filename = "../../$temp/inc/hello.php";
        if (file_exists($filename))
                {
            require $filename;
                fwrite($fh, "Domain: $DOMAIN_NAME
                ");
                }
        $count2++;
 
    }
else
    {
        $count2++;
    }
        fclose($fh);
}
Thank you for any help you can give
~Monotoko

Re: Finding only directries?

Posted: Mon Aug 17, 2009 11:37 am
by JAB Creations
*EDIT* I misread the thread, my bad. :oops:

Start with these...
http://php.net/is-file
http://php.net/is-dir

I'm not exactly sure how to loop through all the directories though I think these functions will help you out. Subscribed.

Re: Finding only directries?

Posted: Mon Aug 17, 2009 6:25 pm
by John Cartwright
Use glob() with the GLOB_ONLYDIR modifier.