#-*-coding:utf-8-*-
'''
Created on 2015年12月28日
@author: Zroad
'''
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
if __name__ == "__main__":
search_path = "E:\\PythonTest" + os.pathsep + "E:\\src"
find_file = search_file("Log4JTest.jar",search_path) #E:\src\Log4JTest.jar
if find_file:
print "File 'Log4JTest.jar' found at %s" % find_file
else:
print "File 'Log4JTest.jar' not found"
从指定的搜索路径寻找文件
最新推荐文章于 2021-04-29 15:59:45 发布