python实现,按文件名搜索制定路径下的文件

#!/usr/bin/env python3
# coding=utf-8

import os

def search(path=".", name="1"):
    for item in os.listdir(path):
        item_path = os.path.join(path, item)
        if os.path.isdir(item_path):
            search(item_path, name)
        elif os.path.isfile(item_path):
            if name in item:
                print(item_path)

if __name__ == "__main__":
    search(path=r"D:\360",name="dll")

你可能感兴趣的:(python)