python遍历文件夹找到指定后缀名结尾的文件


def list_allfile(path, all_files=[], all_py_files=[]):
    if os.path.exists(path):
        files = os.listdir(path)
    else:
        print('this path not exist')
    for file in files:
        if os.path.isdir(os.path.join(path, file)):
            list_allfile(os.path.join(path, file), all_files)
        else:
            all_files.append(os.path.join(path, file))
    for file in all_files:
        if file.endswith('.js'):
            all_py_files.append(file)
    return all_py_files

if __name__ == "__main__":
    js_list = list_allfile(r"~/下载/dist/static/js")
    print(js_list)

从小白到大神的蜕变~~
原文地址:https://www.cnblogs.com/tjw-bk/p/15386932.html