Forum Moderators: coopster

Message Too Old, No Replies

include(); - make it include all files in directory?

include(); multiple files, include directory

         

al1911

1:35 pm on Jan 21, 2005 (gmt 0)

10+ Year Member



i want to include(); a number of files that all reside in the same directory, but the names of the files change and every now and then a new file is touched and an old one is unlinked. is there a way i can just tell php to include all files in the given directory, regardless of what they are and what their names are?

coopster

4:04 pm on Jan 21, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, al1911.

I suppose you could loop through the directory and include them that way...

$d = dir("/path/to/my/includes"); 
while (false!== ($filename = $d->read())) {
if (substr($filename, -4) == '.inc') { // whatever your includes extensions are
// print them for now:
print "$filename\n";
// include them once you like what you see:
// include "$filename";
}
}
$d->close();
exit;

al1911

4:24 pm on Jan 21, 2005 (gmt 0)

10+ Year Member



thanks,
it's the while statement i need to learn more about
your post really helped, i tried it and that code (modified a little) does exactly what i need to do.
thanks again

coopster

4:28 pm on Jan 21, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Sure. Dig into those functions and get to know them. The while [php.net] loop is something you are going to use quite often.