-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathfile_list_listdir_1_0.py
67 lines (64 loc) · 1.76 KB
/
file_list_listdir_1_0.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
#coding=utf-8
import os
import argparse
def showall(path,leavel=0,filenum=0,dirnum=0,show=True,showtype=True,save=False):
newnum = filenum
oldnum = dirnum
currentpath = path;
try:
dirandfile = os.listdir(path)
except:
return 0,0
for item in dirandfile:
newpath = os.path.join(currentpath,item)
if os.path.isdir(newpath):
oldnum = oldnum + 1
tab_stop = ""
if show:
for tab in range(leavel):
tab_stop = tab_stop + " "
if not showtype:
if not save:
print tab_stop + newpath
else:
savefile = open(save,"a")
savefile.write(tab_stop+newpath+"\n")
savefile.close()
num,numdir = showall(newpath,leavel+1,newnum,oldnum,show,showtype,save)
newnum = num
oldnum = numdir
else:
newnum = newnum + 1
tab_stop = ""
if show:
for tab in range(leavel):
tab_stop = tab_stop + " "
if showtype:
if not save:
print tab_stop + newpath
else:
savefile = open(save,"a")
savefile.write(tab_stop+newpath+"\n")
savefile.close()
return newnum,oldnum
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Show All Your File")
parser.add_argument("-o","--on",help="show the inden",action="store_true")
parser.add_argument("-d","--dir",help="show dirs",action="store_true")
parser.add_argument("begin",help="begin your files",action="store",default=r"./")
parser.add_argument("--save",help="print or save files",action="store",default=False)
args = parser.parse_args()
showtype = True
if args.dir:
showtype=False
if args.on:
show = True
else:
show = False
begin = args.begin
save = args.save
filenum,dirnum = showall(begin,show=show,showtype=showtype,save=save)
if showtype:
print "File Number : " + str(filenum)
else:
print "Dir Number : " + str(dirnum)