Discuss / Python / 第二题

第二题

Topic source

import os

def Get_file(path, file_name):

    f_path = os.path.abspath(path)

    #判断是否为所需文件

    L = [x for x in os.listdir(f_path) if os.path.isfile(os.path.join(f_path, x)) and file_name in x ]

    #是的话就打印出来

    for x in L:

        print(os.path.join(f_path, x))

    #判断是否为路径

    LL = [x for x in os.listdir(f_path) if os.path.isdir(x)]

    #是的话进行递归

    for x in LL:

        Get_path(os.path.join(f_path, x), file_name)

Get_file('.', 'test')


  • 1

Reply