forked from souravjain540/Basic-Python-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdirTree.py
More file actions
29 lines (26 loc) · 667 Bytes
/
dirTree.py
File metadata and controls
29 lines (26 loc) · 667 Bytes
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
import os
import os.path
from pathlib import Path
def display(path, level = 0):
try :
path = Path(path)
except:
print("Enter right path")
return
k = os.listdir(path)
for i in k:
if os.path.isfile(os.path.join(path, i)):
print(" "*level, "--F--", i)
elif os.path.isdir(os.path.join(path, i)):
print(" "*level, "+-D--", i)
display(os.path.join(path, i), level = level + 1)
else:
print(i)
return
if __name__ == "__main__":
print("Enter a path")
s = input()
if s == "" :
s = os.getcwd()
l = 0
display(s, level = 0)