This script only outputs the top level. i.e. -/ | - folder1 | - folder2 | - folder3 it should be - / | - folder1 | | | - subdir1 | | | - file1.ext | - folder2 | | | - subdir2 | | | - file2.ext | - folder3 | - subdir3 | - file3.ext I really don't know what I am doing here ;) It looks like something is creating a new class instead of working with $tree, after the foreach loop $branch has the intended value. After $branch =& tree; the added subdirs exist but the files array beneath the subdirs is empty. I'm in way over my head here so if someone could bail me out I would be eternally greatful! Thanks, Jon class dir { var $name; var $subdirs; var $files; var $num; var $prio; function dir($name,$num,$prio) { $this->name = $name; $this->num = $num; $this->prio = $prio; $this->files = array(); $this->subdirs = array(); } function addFile($file) { $this->files[] =& $file; return $file; } function addDir($dir) { $this->subdirs[] =& $dir; return $dir; } function findDir($name) { foreach($this->subdirs as $v){ if($v->name == $name) return $v; } return false; } function draw($parent) { echo('d.add('.$this->num.','.$parent.',"'.$this->name."\",".$this->prio.");\n"); foreach($this->subdirs as $v) { $v->draw($this->num); echo "// Name: ".$v->name."\n// Number: ".$this->num."\n// Subdirs: ".count($v->subdirs)."\n// Files ".count($v->files)."\n"; } foreach($this->files as $v) if(is_object($v)) { echo("d.add(".$v->num.",".$this->num.", \"".$v->name."\",".$v->prio.");\n"); } } } class file { var $name; var $prio; var $size; var $num; function file($name,$num,$size,$prio) { $this->name = $name; $this->num = $num; $this->size = $size; $this->prio = $prio; } } $arFiles = array( array['file1']( array( ['path] => array( [0] => 'folder1', [1] => 'subfolder1' [2] => 'file1.ext' ), ['length'] => 5464, ['size'] => 8765 ), array['file2']( array( ['path] => array( [0] => 'folder2', [1] => 'subfolder2' [2] => 'file2.ext' ), ['length'] => 5464, ['size'] => 8765 ), array['file3']( array( ['path] => array( [0] => 'folder3', [1] => 'subfolder3' [2] => 'file3.ext' ), ['length'] => 5464, ['size'] => 8765 ) ) $prio = array(); for($i=0;$i<count($arFiles);$i++) $prio[$i] = -1; $dirnum = count($arFiles); $tree = new dir("/",$dirnum,isset($prio[$dirnum])?$prio[$dirnum]:-1); foreach( $arFiles as $filenum => $file) { $depth = count($file['path']); $branch =& $tree; for($i=0; $i < $depth; $i++){ if ($i != $depth-1){ $d =& $branch->findDir($file['path'][$i]); if($d) $branch =& $d; else{ $dirnum++; $d =& $branch->addDir(new dir($file['path'][$i], $dirnum, (isset($prio[$dirnum])?$prio[$dirnum]:-1))); $branch =& $d; } }else $branch->addFile(new file($file['path'][$i]." (".$file['length'].")",$filenum,$file['size'], $prio[$filenum])); } } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php