-
Notifications
You must be signed in to change notification settings - Fork 0
/
07FileTree(1).py
41 lines (34 loc) · 938 Bytes
/
07FileTree(1).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
'''
'''
import os
class Count:
def __init__(self,dirCount,fileCount):
self.dirCount = dirCount
self.fileCount = fileCount
def __str__(self):
return dirCount and fileCount
class PrintFileTree(Count):
def __init__(self,path,deep):
super(PrintFileTree, self).__init__(dirCount,fileCount)
self.path = path
self.deep = deep
def printFileTree():
files = os.listdir(self.path)
for f in files:
fpath = path + "/" + f
print("|--"*self.deep,fpath)
if os.path.isdir(fpath):
PrintFileTree.printFileTree(fpath,self.deep + 1)
self.dirCount += 1
else:
self.fileCount += 1
pass
# return dirCount,fileCount
if __name__ == '__main__':
b = PrintFileTree(r"E:/MyProjects/",0)
print(b.printFileTree)
c = Count()
print(c)
# dirCount,fileCount =
printFileTree()
# print(dirCount,fileCount)