0

Hi


i have sub-directories like this (files/dir/dir2/) and have input text

I want to get all the doc files in the sub-directories when insert name of top directory (files)in the text field

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by vibhaJ
0

Try this recursive function.

<?
function directoryToArray($directory, $recursive) {
	$array_items = array();
	if ($handle = opendir($directory)) {
		while (false !== ($file = readdir($handle))) {
			if ($file != "." && $file != "..") {
				if (is_dir($directory. "/" . $file)) {
					if($recursive) {
						$array_items = array_merge($array_items, directoryToArray($directory. "/" . $file, $recursive));
					}
					$file = $directory . "/" . $file;
					$array_items[] = preg_replace("/\/\//si", "/", $file);
				} else {
					$file = $directory . "/" . $file;
					$array_items[] = preg_replace("/\/\//si", "/", $file);
				}
			}
		}
		closedir($handle);
	}
	return $array_items;
}
$arr = directoryToArray('.',true);
echo '<pre>';
print_r($arr );
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.