Discuss / Python / 笔记

笔记

Topic source
import os


def search(name, list=None, dirpath=None):
    if list is None:
        list = []  # 集合
    if dirpath is None:
        dirpath = os.path.abspath('.')  # 当前绝对路径

    for x in os.listdir(dirpath):
        abx = os.path.join(dirpath, x)  # 拼接路径
        if os.path.isdir(abx):
            search(name, list, abx)
        if os.path.isfile(abx) and name in x:
            list.append(abx)
    return list


print(search('oo'))

御姐Jmelody

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

递归的方法,厉害了


  • 1

Reply