Jump to content

is there a way to include all of the files in a directory?


emehrkay

Recommended Posts

If you got php5:

<?php

$dir = "includes/";
$cont = scandir($dir);
foreach ($cont as $file)
{
if(is_file($file))
	include($file);
}

?>

 

If you have php4, add this function the the code:

<?php
function php4_scandir($dir,$listDirectories=false, $skipDots=true) {
   $dirArray = array();
   if ($handle = opendir($dir)) {
       while (false !== ($file = readdir($handle))) {
           if (($file != "." && $file != "..") || $skipDots == true) {
               if($listDirectories == false) { if(is_dir($file)) { continue; } }
               array_push($dirArray,basename($file));
           }
       }
       closedir($handle);
   }
   return $dirArray;
}
?>

 

 

Orio.

thanks orio

 

this is what i took directly from the site with a slight modification

 

<?php
/**
* requre all of the schema files
*/
if($handle = opendir(CLASS_PATH.'ertool/schema/')){
while(false !== ($file = readdir($handle))) {
	if($file != '.' && $file != '..'){
		require_once(CLASS_PATH. 'ertool/schema/'. $file);
	}
}
closedir($handle);
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.