public function read_dir($path, $preserve_filepath = TRUE, $root_path = NULL)
{
$path = rtrim($path, '/\\') . DIRECTORY_SEPARATOR;
if (!($fp = @opendir($path))) {
return FALSE;
}
// Set the original directory root for child dir's to use as relative
if ($root_path === NULL) {
$root_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, dirname($path)) . DIRECTORY_SEPARATOR;
}
while (FALSE !== ($file = readdir($fp))) {
if ($file[0] === '.') {
continue;
}
if (is_dir($path . $file)) {
$this->read_dir($path . $file . DIRECTORY_SEPARATOR, $preserve_filepath, $root_path);
} elseif (FALSE !== ($data = file_get_contents($path . $file))) {
$name = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $path);
if ($preserve_filepath === FALSE) {
$name = str_replace($root_path, '', $name);
}
$this->add_data($name . $file, $data);
}
}
closedir($fp);
return TRUE;
}