Jump to content


Photo

Help with directory scan code (beginner)


  • Please log in to reply
1 reply to this topic

#1 Tarantulus

Tarantulus
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 05 September 2006 - 07:23 PM

Hi there,
I got this code from another site, and I understand how it works, but I can't get the results to display as text.

<?php

function scan_directory_recursively($directory, $filter=FALSE)
{
	if(substr($directory,-1) == '/')
	{
		$directory = substr($directory,0,-1);
	}
	if(!file_exists($directory) || !is_dir($directory))
	{
		return FALSE;
	}elseif(is_readable($directory))
	{
		$directory_list = opendir($directory);
		while($file = readdir($directory_list))
		{
			if($file != '.' && $file != '..')
			{
				$path = $directory.'/'.$file;
				if(is_readable($path))
				{
					$subdirectories = explode('/',$path);
					if(is_dir($path))
					{
						$directory_tree[] = array(
							'path'      => $path,
							'name'      => end($subdirectories),
							'kind'      => 'directory',
							'content'   => scan_directory_recursively($path, $filter));
					}elseif(is_file($path))
					{
						$extension = end(explode('.',end($subdirectories)));
						if($filter === FALSE || $filter == $extension)
						{
							$directory_tree[] = array(
							'path'		=> $path,
							'name'		=> end($subdirectories),
							'extension' => $extension,
							'size'		=> filesize($path),
							'kind'		=> 'file');
						}
					}
				}
			}
		}
		closedir($directory_list); 
		return $directory_tree;
	}else{
		return FALSE;	
	}
}
echo $directory_tree[]


?>

I've tried echo $directory_list [name];

and such but nothing seems to work, i need the output to have in a javascript expanding menu.

hope this makes sense I am a REAL beginner

#2 karthikeyan_coder

karthikeyan_coder
  • Members
  • PipPipPip
  • Advanced Member
  • 201 posts

Posted 05 September 2006 - 08:24 PM

just try this
print_r($directory_list);
Make sure that the array is having values...
www.karthi.us




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users