现在的位置: 首页 > 综合 > 正文

002_018 Python 查找目录中的第一个文件,指定类型

2018年02月15日 ⁄ 综合 ⁄ 共 372字 ⁄ 字号 评论关闭

代码如下:

#encoding=utf-8

print '中国'

#查找目录中的第一个文件,指定类型

import os

def search_file(filename, search_path, pathsep = os.pathsep):
    for path in search_path.split(pathsep):
        candidate=os.path.join(path,filename)
        if os.path.isfile(candidate):
            return os.path.abspath(candidate)
    return None


print search_file(r'ft.ini', r'H:\football\GetFootballMatch\Release')

打印结果如下:

中国
H:\football\GetFootballMatch\Release\ft.ini

抱歉!评论已关闭.