Hello there,

I need a simple function which do something like tihs:
I have folders like this:
ext/test1/test1/index.html
ext/test2/
ext/test1/test2/index.html
ext/test3/

I need a function which gives me only folders with subfolders and files in it.
The condition is to give a "ext/" folder in the function :)

function get_subdirs('ext/') {//code}}

When this function runs, i need only following:
test1/test2
test1/test1
(only folders with subfolders with files in it in ext/ folder)

Thanks to anyone who help me!

I see this thread before write here. I can't do this myself.

Ivan,

Can you explain what you mean by you can't do this yourself? I'm seeing a lot of folk want others to write the code and more. I don't mind kicking around ideas but like most forums with free help, no one seems to write your app for you.

Yes, i know that.
I try with this:

function expandDirectories($base_dir) {
      $directories = array();
      foreach(scandir($base_dir) as $file) {
            if($file == '.' || $file == '..') continue;
            $dir = $base_dir.DIRECTORY_SEPARATOR.$file;

            if(is_dir($dir) && dir_contains_children_dirs($dir)) {

                $directories []= $dir;
                $directories = array_merge($directories, expandDirectories($dir));
            }
      }
      return $directories;
}

function dir_contains_children_dirs($dir) {
  $result = false;
    if($dh = opendir($dir)) {
       while (!$result && ($file = readdir($dh))) {
         $result = $file !== "." && $file !== ".." && is_dir($dir.'/'.$file);
       }
       closedir($dh);
    }

  return $result;
}


$directories = expandDirectories('../ext');
print_r($directories);

but not gives me the subdirs. Only dirs with subdirs.
The return is:
test1
Not:
test1/test2
test1/test1

How are you debugging this?

When I need to figure this out I'll add more print statements so I can see inside the functions and pick up where I went off the rails.

Example: After say line 8 add a print so you can see what's going on inside that function.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.