Query::Arrays - Correct Usage
Posted: Mon May 24, 2004 4:53 pm
Alright...
I am TRYING to build a Class where part of it is used to traverse a Directory. I have been using opendir and readdir to grab the files...
However, I WANT to skim through a directory...
As I go THROUGH the directory...
I want to add File / Folder names to an Array...
As I hit a Folder, I ALSO want to skim through it and do the same...
Kinda a repeat...
I am as lost as they get...
I THOUGHT I had it figured out...
Here are some pieces of the class...
If you can help with this, I would be greatly appreciative... I am just lost. It could be that I have never fully grasped Arrays. I understand the concept, but I have never had a real world explanation that made sense... Ah well...
I am TRYING to build a Class where part of it is used to traverse a Directory. I have been using opendir and readdir to grab the files...
However, I WANT to skim through a directory...
As I go THROUGH the directory...
I want to add File / Folder names to an Array...
As I hit a Folder, I ALSO want to skim through it and do the same...
Kinda a repeat...
I am as lost as they get...
I THOUGHT I had it figured out...
Here are some pieces of the class...
Code: Select all
function _FolderListing( $path )
{
if ( $handle = opendir( $path ) )
{
$folders = explode( "/", $path );
$Number = count( $folders ) - 2;
$folder = $folders[$Number];
while ( False !== ( $file = readdir( $handle ) ) )
{
$ItemNumber = count( $this->Folder ) - 1;
if ( $file != "." && $file != ".." )
{
$this->Folder[$folder] = array
(
'itemID' => ,
'itemName' => $file,
'itemPath' => $path,
'itemFULLPath' => $path . $file,
'itemType' => ( is_file( $path . $file ) ) ? "File":"Folder"
);
if( $this->Folder[$folder]['itemType'] == "Folder" )
{
$newPath = $path . $file . "/";
$this->_FolderListing( $newPath );
}
}
}
closedir( $handle );
}
}
function TEST( )
{
$this->_FolderListing( $this->_pathToPackage( 'coreSystem' ) );
$test = $this->BreakDown( $this->Folder );
Return $test;
}
function BreakDown( $arr )
{
$temp .= "<table border="1">";
$temp .= "<tr><td>key</td><td>val</td></tr>";
foreach( $arr as $key=>$val )
{
if( is_array( $val ) )
{
$temp .= "<tr><td>$key</td<td>" . $this->BreakDown( $val ) . "</td><>tr>";
}
else
{
$temp .= "<tr><td>$key</td><td>$val</td></tr>";
}
}
$temp .= "</table>";
Return $temp;
}