forked from kallaway/100-days-of-code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
folder_sructure.py
71 lines (61 loc) · 2.15 KB
/
folder_sructure.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
global beginning_directory
global structure
def build_tree():
rootDir = '.'
path = "/home/intern-chieto/Documents/chieto/B/"
path_split = path.split("/")
figure = len(path_split)
dirr = {path_split[figure - 2]: {}}
beginning_directory = dirr[path_split[figure - 2]]
list_of_next_dir = [path_split[figure - 2]]
structure = ""
for dirName, subdirList, fileList in os.walk(path):
paths = dirName.split("/")
list_of_next_dir = [path_split[figure - 2]]
for pathh in paths:
if paths.index(pathh) < figure - 1:
pass
else:
list_of_next_dir.append(str(pathh))
try:
obj = {}
for next_dir in range(len(list_of_next_dir)):
if next_dir == 0:
obj = dirr[list_of_next_dir[next_dir]]
if next_dir > 0:
obj = obj[list_of_next_dir[next_dir]]
for sub_dir in subdirList:
obj[sub_dir] = {}
structure += "|-----" + sub_dir + "-----" + "\n"
for i in range(3):
structure += "|" + "\n"
for files in fileList:
obj[files] = None
structure += "|-----" + files + "\n"
print(obj)
# for key in obj.keys():
# if obj[key] != None:
# structure += "|-----" + key + "-----" + "\n"
# for i in range(3):
# structure += "|" + "\n"
# else:
# structure += "|-----" + key + "\n"
except Exception as exception:
print(exception)
draw_tree(beginning_directory, structure)
def draw_tree(directory, structure):
for key in directory.keys():
if directory[key] != None:
structure += "|-----" + key + "-----" + "\n"
for i in range(3):
structure += "|" + "\n"
else:
structure += "|-----" + key + "\n"
print(directory)
print(structure)
# draw_tree(directory, structure)
try:
build_tree()
except Exception as exception:
print(exception)