Finding only directries?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Monotoko
Forum Commoner
Posts: 64
Joined: Fri Oct 26, 2007 4:24 pm

Finding only directries?

Post 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
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Finding only directries?

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Finding only directries?

Post by John Cartwright »

Use glob() with the GLOB_ONLYDIR modifier.
Post Reply