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

来源:互联网 发布:手机淘宝首页登陆 编辑:程序博客网 时间:2024/05/17 07:19

代码如下:

#encoding=utf-8print '中国'#查找目录中的第一个文件,指定类型import osdef 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 Noneprint search_file(r'ft.ini', r'H:\football\GetFootballMatch\Release')

打印结果如下:

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

0 0
原创粉丝点击