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
posted @ 2017-03-27 13:28  idlewith  阅读(99)  评论(0编辑  收藏  举报