From 99e0e8e61546e3bf1b7b49844dee51ba79eaa107 Mon Sep 17 00:00:00 2001 From: aditya-K2 Date: Mon, 11 Oct 2021 11:42:00 +0530 Subject: [PATCH] Added generateDirectoryTree() This function which generates a Directory Tree from a given path string for e.g if the String that is given is "home/what/dir" , "home/hello/foo" then it will return a FileNode ( Struct ) which looks like this head{ [{ [ { [ { [] dir } ] what }, { [ { [] foo } ] hello } ] home }] "root" } --- fileBrowser.go | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/fileBrowser.go b/fileBrowser.go index 4727ccb..f7cab5f 100644 --- a/fileBrowser.go +++ b/fileBrowser.go @@ -2,6 +2,7 @@ package main import ( "strings" + "fmt" ) type FileNode struct{ @@ -19,29 +20,32 @@ func (f *FileNode) addChildNode(m FileNode){ f.children = append(f.children, m) } -func mapGenerator(fileList [] string) map[string][]string { - var a map[string][]string = make(map[string][]string) - for i := range(fileList){ - a[strings.Split(fileList[i] , "/")[0]] = append(a[strings.Split(fileList[i] , "/")[0]], strings.Split(fileList[i] , "/")[1]) - } - return a -} - -func generateDirectoryTree(fileList [] string) *FileNode{ +func generateDirectoryTree(path [] string) *FileNode{ var head *FileNode = new(FileNode) - for i:=0; i