tags:

views:

44

answers:

2

Hello,

I have "content" folder which is full of other sub-directories named in the following way: "id1_1","id1_2", "id1_3" and other "id2_1", "id2_2" etc. Each of these folders contains a file "template.php", same name in all sub-directories.

The number of folders is dynamic so I need to find a way to import in "index.php" only the "template.php" from all the folders starting with "id_1_".

How can I do it? Thanks!

+1  A: 

You can use a recursive function + foreach + glob:

http://www.php.net/glob

Tim Green
Just to add: recursion will only needed if you need to descend into infinite depth (i.e. sub-sub-sub folders), but by the sounds of it, you might not need it.
Tim Green
+3  A: 

You can use the glob() function:

$arrFiles = glob('./id_1_*/template.php');
foreach($arrFiles as $file) {
     include_once($file);
}
Mark