Okay... if I understand your situation correctly, you have a directory structure similar to:
./ (current working directory)
[indent]+ Text/
[indent]+ various-other-directories/ ( $d in existing code )
[indent]+ Comments/ (in each directory $d)[/indent][/indent][/indent]
correct?
<?php
$dir = glob( './Text/*',GLOB_ONLYDIR );
foreach( $dir as $d ){
$filename = "$d/All.html";
if( file_exists( $filename ) ){
include $filename;
#if you only want to look for /Comments when $filename exists, put the loop here.
# otherwise, put it outside `if (file_exists)` but inside the `foreach()` loop.
$sub_dir = glob( "$d/Comments/*",GLOB_ONLYDIR ); #<-- note! "double quotes"
foreach( $sub_dir as $sd ){
$s_filename = "$e/All.php";
if( file_exists( $s_filename ) ){ include $s_filename; }
}
}
}
As I posted above, if you put that second loop somewhere else, it won't have access to each [font=monospace]$d[/font].
As an aside, you sure seem to be blanket-including a lot of files here, some of which may or may not exist.
Are you sure there isn't a better design to solve your problem?
(I don't know what the application is, here, but it looks like a database might be helpful...?)