Problem with my Recursive function

Hi,

I am trying to loop over and search for a specific path.

I use recursion to go over all the folders, get the path to the root, and compare the folder's path to the path string I sent.

Something here is not working properly.

I will be happy if someone can have a second look to see what went wrong:

this.childFolder = stcmd.getSpecifiedFolder(childFolderPath,v1);

protected Folder getSpecifiedFolder (String path ,String viewName){

/* Search for StarTeam folder using specific path*/

View tempView = getView(viewName);

Folder rootFolder = tempView.getRootFolder();

if (rootFolder.getPath().equals(path)){

return rootFolder;

}

else{

Folder folder = getFolder(rootFolder,path);

return folder;

}

}

private Folder getFolder(Folder rootFolder, String path){

Folder[] folderList = rootFolder.getSubFolders();

for (int i = 0 ; i < folderList.length ; i++){

String currentPath = folderList[i].getFolderHierarchy();

if (currentPath.equals(path)){

return folderList[i];

}

else{

getFolder(folderList[i],path);//Recursion.

}

}

returnnull;

}

[2079 byte] By [Ilan_Yaniva] at [2007-11-27 5:52:01]
# 1
> Something here is not working properly.You want to give us a clue? Are you getting some error? going into an infinte loop? Have you tried echoing info back to you with System.out? Do you know what a debugger is?
_helloWorld_a at 2007-7-12 15:42:04 > top of Java-index,Java Essentials,Java Programming...
# 2

Hi Sorry.

1) Well the code is OK and running.

2) Yes, I am using a debugger.

3) I am not using System.out....

4) It appears that the recursion is NOT running all over the tree. It is going down the first leaf and ends.

for example if I have a root folder: A

and under there are two sub folders B,C

I am going down the B tree and leave the C folder unhandled.

Ilan_Yaniva at 2007-7-12 15:42:04 > top of Java-index,Java Essentials,Java Programming...
# 3

Hey, where is the help that I am looking for....

So I have changed the functions, look at them

protected Folder getSpecifiedFolder (String path ,String viewName){

/* Search for StarTeam folder using specific path*/

View tempView = getView(viewName);

Folder rootFolder = tempView.getRootFolder();

if (rootFolder.getPath().equals(path)){

return rootFolder;

}

else{

Folder[] folderList = rootFolder.getSubFolders();

Folder folder = getFolder(folderList[0],0,path);

return folder;

}

}

private Folder getFolder(Folder subFolder, int i, String path){

String tempPath = subFolder.getFolderHierarchy();

if (tempPath.equals(path)){

return subFolder;

}

//if (subFolder.getSubFolders()[i] == null){

if (subFolder.getSubFolders().length == 0){

return null;

}

if (subFolder.getSubFolders().length > 0) {

i = 0;

}

else{

i++;

}

return getFolder(subFolder.getSubFolders()[i] , i, path);

Ilan_Yaniva at 2007-7-12 15:42:04 > top of Java-index,Java Essentials,Java Programming...