Discuss / Python / 第二题

第二题

Topic source
import os

def dirfind(filename,path = os.getcwd()):
    temp_path = os.getcwd()
    os.chdir(path)
    for x in os.listdir('.'):
        if os.path.isfile(x):
            if filename in os.path.splitext(x)[0]:
                print(os.path.relpath(x))
        if os.path.isdir(x):
            path = os.path.abspath(x)
            dirfind(filename,path)
            os.chdir(temp_path)

if __name__ == '__main__':
    dirfind('tes')

  • 1

Reply