Discuss / Python / 作业2

作业2

Topic source

#1 Created at ... [Delete] [Delete and Lock User]

# _*_coding:utf-8_*_

import os

def GetList(dir, keyword='') -> list:

    l = []

    for x in os.listdir(dir):

        if os.path.isdir(dir+'/'+x):

            GetList(dir+'/'+x)

        else:

            if x.find(keyword) != -1:

                l.append(x)

    return l

try:

    print(GetList('.', 'x'))

except OSError as e:

    print('there is a error: %s' % e)


  • 1

Reply