Discuss / Python / 第二个

第二个

Topic source

冰月冷望

#1 Created at ... [Delete] [Delete and Lock User]
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os

def finder(pattern, root='.'):
    matches = []
    dirs = []

    for x in os.listdir(root):
        nd=os.path.join(root, x)
        if os.path.isdir(nd):
            dirs.append(nd)

        elif os.path.isfile(nd) and pattern in x:
            matches.append(nd)

    for match in matches:
        print(match)

    for dir in dirs:
        finder(pattern, root=dir)

finder('err',root='/usr')

  • 1

Reply