-
Notifications
You must be signed in to change notification settings - Fork 0
/
traversal.py
34 lines (24 loc) · 846 Bytes
/
traversal.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
import os
# Using Recurssion
def traverse(path):
hash = {}
hash1 = {}
for dir, folders, files in os.walk(path):
folders.extend(files)
for i in folders:
if os.path.isfile(os.path.join(dir, i)):
hash1[i] = 0
else:
hash1[i] = traverse(os.path.join(dir, i))
wis = hash[os.path.basename(dir)] = hash1
return wis
# Using Recurssion
def create_traversal(hash, destination_dir):
for i in hash:
if os.path.splitext(os.path.join(destination_dir, i))[1] != "" or type(hash[i]) == int:
f = open(os.path.join(destination_dir, i), "w")
f.close()
else:
true_path = os.path.join(destination_dir , i)
os.makedirs(true_path)
create_traversal(hash[i], true_path)