find the first t.py file through traversal C: and D:

import os
import fnmatch

def get_c_path():
    for drive in ('C:\', 'D:\'):
        for dirpath, dirnames, filenames in os.walk(drive):
            for name in filenames:
                if fnmatch.fnmatch(name, 't.py'):
                    path_app = os.path.join(dirpath, name)
                    if os.path.isfile(path_app):
                        return path_app
原文地址:https://www.cnblogs.com/otfsenter/p/6626278.html