Skip to content

Latest commit

 

History

History
26 lines (21 loc) · 555 Bytes

107.md

File metadata and controls

26 lines (21 loc) · 555 Bytes
@author jackzhenguo
@desc 
@date 2019/10/6

107 获取指定后缀名的文件

import os

def find_file(work_dir,extension='jpg'):
    lst = []
    for filename in os.listdir(work_dir):
        print(filename)
        splits = os.path.splitext(filename)
        ext = splits[1] # 拿到扩展名
        if ext == '.'+extension:
            lst.append(filename)
    return lst

r = find_file('.','md') 
print(r) # 返回所有目录下的md文件
[上一个例子](106.md) [下一个例子](108.md)