# Scanning through subdirectories

**URL:** https://forum.kirupa.com/t/scanning-through-subdirectories/311005
**Category:** programming
**Created:** [June 25, 2010, 12:09am UTC](https://forum.kirupa.com/t/scanning-through-subdirectories/311005 "2010-06-25T00:09:35Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![dreamerp](https://avatars.discourse-cdn.com/v4/letter/d/fbc32d/32.png) [@dreamerp](https://forum.kirupa.com/u/dreamerp)
#### Post date: [June 25, 2010, 12:09am UTC](https://forum.kirupa.com/t/scanning-through-subdirectories/311005/1 "2010-06-25T00:09:35Z")

</div>

Hey,

I am writing a PHP backup script that should be recursive in order to search through sub directories. But, before I make it recursive, I need to figure out why it is not recognizing subdirectories as directories? I used the PHP code provided on the PHP manual web site, but added in a line just to test out printing subdirectory names:

```php
if ($handle = opendir($directory)) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            echo "<br />$file
";
        } elseif (is_dir($file)){ echo "<br />Directory: $file"; }
    }
    closedir($handle);
}

```

I was thinking… do permissions on folders have anything to do with this? Why won’t it recognize subdirectories as a TRUE in is\_dir($file)? Right now it only prints out “.” and “…” as directories but the subdirectories print as if they are files.

Anyone have any ideas?
