文件查找功能

1
####查找文件
def find_file_by_pattern(pattern='.*',base='.',circle=True):
    re_file=re.compile(pattern)
    if base=='.':
        base=os.getcwd()
    final_file_list=[]
    #print base
    cur_list=os.listdir(base)
    #print cur_list
    for item in cur_list:
        full_path=os.path.join(base,item)
        #print full_path
        if os.path.isfile(full_path):
            if re_file.search(full_path):
                final_file_list.append(full_path)
        else:
            final_file_list+=find_file_by_pattern(pattern,full_path)
    return final_file_list

2

#####查找文件new
def find_file_by_pattern1(match='*',base='.'):
    if base=='.':
        base=os.getcwd()
    cfiles = [os.path.join(root, filename)
    for root, dirnames, filenames in os.walk(base)
    for filename in filenames if filename.endswith(match)]    
    return cfiles


你可能感兴趣的:(python,文件查找)