-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpytree.py
44 lines (30 loc) · 895 Bytes
/
pytree.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
from os import listdir
from os.path import abspath, basename, isdir, isfile, sep
from sys import argv
import argparse
def tree(path, tab):
print('\n'+tab+basename(path) + '-|')
tab += ' '
files = dirs = []
try:
dirs = [item for item in listdir(path) if isdir(path+sep+item)]
files = [item for item in listdir(path) if isfile(path+sep+item)]
except:
pass
for file in files:
# first print all files then go to directories
print(tab+'-'+file)
for dir in dirs:
tree(path+'\\'+dir, tab)
def main(path):
if isdir(path):
tree(path, '')
else:
print("Wrong Input..")
return
print('\n')
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="pytree")
parser.add_argument("path", help="Path of request directory")
args = parser.parse_args()
main(args.path)