473,322 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

tree built recursive

Hello developers!

I'm sticking in a problem.

I want to read the folder hierarchy of the webserver and store the
information in a tree, built like a linked list - you know 'a tree'.

you see in function readsubtree() i'm storing the object child in the
array of the actualfoldernode. but this doesn't work out. it never
arrives there.

the tree is just built to one depth. although the recursion works as
some echo outs show.

please help

cheers
a-k

let me post in the snippet:

function readTree(){
global $name_of_root;
$this->rootNode = new FolderTreeNode($this);
$this->rootNode->name = $name_of_root;
$this->rootNode->absPath = absolutePath("");
if (relativePath(getcwd()) == "") {$this->rootNode->selected = true;}
$this->readSubTree(&$this->rootNode);
}

function readSubTree($actualFolderNode){
$actualAbsDir = $actualFolderNode->absPath;
$dir = @opendir($actualAbsDir);
if (!$dir) {return 0;}
while ($entry = readdir($dir)){
if (is_dir($actualAbsDir."/".$entry) && ($entry != ".." && $entry !=
".")){
$child = new FolderTreeNode($this);
$child->name = $entry;
$child->absPath = $actualAbsDir."/".$entry;
$child->parentNode = $actualFolderNode;
if (getcwd() == $child->absPath) {$child->selected = true;}
$actualFolderNode->childNodes[] = $child;
$this->readSubTree($child);
}
}
}

class FolderTreeNode{

var $folderTree;

var $name;
var $absPath;
var $parentNode;
var $childNodes = array();
var $selected;
var $newElements;
function FolderTreeNode($folderTree){
$this->folderTree = $folderTree;
}
}
Jul 16 '05 #1
2 6201
andreas kirschner wrote:
Hello developers!

I'm sticking in a problem.

I want to read the folder hierarchy of the webserver and store the
information in a tree, built like a linked list - you know 'a tree'.

you see in function readsubtree() i'm storing the object child in the
array of the actualfoldernode. but this doesn't work out. it never
arrives there.

the tree is just built to one depth. although the recursion works as
some echo outs show.

please help

cheers
a-k

let me post in the snippet:

function readTree(){ <snip>
Guess this is OK. }

function readSubTree($actualFolderNode){ <snip>
This code looks OK too, except your function declaration needs to pass
the $actualFolderNode by reference instead of as a regular var.

function readSubTree(&$actualFolderNode) {

unless you're using PHP 5.0, which is supposed to do this automatically.

If you don't pass by reference, $actualFolderNode is a copy of the
object you're passing into the function, not the actual object itself.
}


Jason

Jul 16 '05 #2
I solved the problem:

the instantiation is now made as a reference as well as the storing in
the childnodes array

function readSubTree(&$actualFolderNode){
$actualAbsDir = $actualFolderNode->absPath;
$dir = @opendir($actualAbsDir);
if (!$dir) {return 0;}
while ($entry = readdir($dir)){
if (is_dir($actualAbsDir."/".$entry) && ($entry != ".." && $entry
!= ".")){
$child = &new FolderTreeNode($this);
$child->name = $entry;
$child->absPath = $actualAbsDir."/".$entry;
$child->parentNode = $actualFolderNode;
if (getcwd() == $child->absPath) {$child->selected = true;}
$actualFolderNode->childNodes[] = &$child;
$this->readSubTree($child);
}
if (is_file($actualAbsDir."/".$entry)){
if (strtotime("-".$this->wExplorer->coloredDays." days") <
(filemtime($actualAbsDir."/".$entry))){
$actualFolderNode->newElements = true;
}
}
}
closedir($dir);
}
Jul 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: t_pet422 | last post by:
Hi, I've been scouring the net and reading the PostgreSQL docs for a while now trying to learn how to create a recursive function in PL/pgSQL that will return a whole subtree given a starting...
4
by: Jerry Khoo | last post by:
Thanks for the answer, and by the way, i would like to know that in C++, how u create a tree using a recursive envronment. It seems that most people used struct to create a node than, using...
4
by: Henry Jordon | last post by:
I have everything pretty much done but I need to fix something in my coding. I want to be able to enter strings such as "love", "hate", "the", etc. but am unable to figure how to do this. I have...
12
by: pillepop2003 | last post by:
Hey! Can anyone give me a hint, how this problem is best implemented: I have a table of users (see below), where every user has one "superior user" (= parent node), this should be a fully...
13
by: hornedw | last post by:
I have been working on a ecommerce website for myself. What I needed some assistance on was when i was trying to display the categories/subcategories for the different products. I decided to use...
9
by: Steve Edwards | last post by:
Hi, I have a class which contains a single ptr to another instance which is considered its parent, and an array of ptrs to its children class Nodes{ .... Nodes *mSuper;
15
lwwhite
by: lwwhite | last post by:
I'm not sure if this discussion is a better fit for the Access or XML forum and I don't want to double-post, so I'm starting in Access because you've been so helpful to me here. I am preparing a...
2
by: aemado | last post by:
I am writing a program that will evaluate expressions using binary trees. Most of the code has been provided, I just have to write the code for the class functions as listed in the header file....
13
by: Bill Cunningham | last post by:
pgs 140-1 of kandr2 talk about recursion. I tried typing in the code char by char and couldn't find the bugs so I just read the code and a new concept to me jumped out. Maybe this is what it means...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.