@Scrazy
2016-11-29T12:24:50.000000Z
字数 507
阅读 809
python
import os
from collections import deque
def search_file(file_format, path=None):
if path is None:
path = os.getcwd() # 默认为自家目录
Q = deque(os.listdir(path))
while Q:
u = Q.popleft()
child_path = os.path.join(path, u)
if not os.path.isdir(child_path):
file = os.path.split(child_path)[1]
suffix = file.split('.')[1]
if suffix == file_format:
print(file)
if __name__ == '__main__':
path = input('Please input the path {} >'.format('\n'))
if path == '':
path = None
file_format = input('Please input the file type {} >'.format('\n'))
search_file(file_format, path)