0

I have this tree structure.

FolderTree

How can i generate a folder path from it;

something like: folder1/chilfolder1/childfolder2/childfolder3

Do this for all folders in the tree :)

  • What did You try already ? Maybe recursion search ? – Fincio Mar 10 '16 at 14:23
  • Yeah How can i do that ? – AndroidCoda Mar 10 '16 at 14:36
  • 1
    I think the best way is to search for some information, like this : http://stackoverflow.com/questions/2056221/recursively-list-files-in-java I've spend whole 5 seconds to get this topic ;) – Fincio Mar 10 '16 at 14:38
  • possible duplicate of [How to recursively list all the files in a directory](http://stackoverflow.com/questions/929276/how-to-recursively-list-all-the-files-in-a-directory-in-c) – esiprogrammer Mar 10 '16 at 14:43
  • please look at the image i sent with the question. I need to loop throught Json file wich contins folders with child folders. – AndroidCoda Mar 10 '16 at 14:49

2 Answers2

0

The objects that you are referring to as files and folders are just objects inside of a JSON serialized object. So, if you want to go about making URIs (Unique Resource Identifiers), you should analyze this data and go node by node down into the object, adding a \ (path seperator) and a String value of the current node name.

Patrick Bell
  • 769
  • 3
  • 15
0

The easiest way would be using a well-known depth-first search algorithm. Consider the following c# pseudo-code:

class Node {
   public string Name;
   public IEnumerbale<Node> Children;
}

void Main(){
   var tree = new List<Node>();//fill it somehow
   foreach(var node in tree){
      DFS(node);
   }
}

void DFS(Node root){
   foreach(var node in root.Children){
      node.Name = root.Name + '/' + node.Name;
      DFS(node);
   }  
}

After you run this code you'll get full names stored in Name property of each Node

Oleg Golovkov
  • 596
  • 1
  • 4
  • 18