Discuss / Python / 第二问

第二问

Topic source

露心

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

import os

def find(s, name):

    d = [x for x in os.listdir(s) if os.path.isdir(os.path.join(s, x))]#当前目录下的所有子目录

    f = [x for x in os.listdir(s) if os.path.isfile(os.path.join(s, x)) and name in os.path.splitext(x)[1]]

    for x in f:

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

    for x in d:

        g = os.path.join(s, x)

        find(s, name)#目录递

范伟

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

你好,我想问一下,为什么不直接用d = os.listdir(s),而用 d = [x for x in os.listdir(s) if os.path.isdir(os.path.join(s, x))]


  • 1

Reply