import os,optparse
#1:精确查找
def search_file(filename, search_path=os.environ['PATH'], pathsep=os.pathsep):#os.pathsep是分隔符';'
    for path in search_path.split(os.pathsep):
        candidate = os.path.join(path, filename)#预选路径
        if os.path.isfile(candidate):
            yield os.path.abspath(candidate) #用生成器可以方便控制返回的数据.可以使用.next()等方法只返回下一个子项
def parse_args():#帮助提示
    usage = u'''这是一个查找文件夹路径中是否有文件指定文件的
脚本,
第一个参数是要找的文件名,第二个是路径'''
    parser = optparse.OptionParser(usage)
    help = u'要查找的文件名字'
    parser.add_option('--filename', help=help)#type='int',
    help = u'查找的路径多个路径以;分隔'
    parser.add_option('--path', help=help, default='e:')
    options, args = parser.parse_args()
    return options, args
if __name__ == '__main__':
    options, args = parse_args()
    find_file = list(search_file(args[0], args[1]))
    if find_file:
        for file in find_file:
            print "Found File at %s" % file
    else:
        print "Not Found"