forked from lymin/python_interview_question
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path19.py
More file actions
33 lines (28 loc) · 699 Bytes
/
19.py
File metadata and controls
33 lines (28 loc) · 699 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
30
31
32
33
import os
'''
def get_pycfile(dir, suffix):
res = []
for root, _, files in os.walk(dir):
for filename in files:
_, suf = os.path.splitext(filename)
if suf == suffix:
res.append(os.path.join(root, filename))
print(res)
get_pycfile("./", ".pyc")
'''
#方法二
def pick(obj):
if obj.endswith('.pyc'):
print(obj)
def scan_path(ph):
file_ls = os.listdir(ph)
print(file_ls)
for obj in file_ls:
if os.path.isfile(obj):
pick(obj)
elif os.path.isdir(obj):
scan_path(obj)
print(obj)
if __name__ == '__main__':
path = input("please input dir:")
scan_path(path)