Discuss / Python / 打卡

打卡

Topic source

Pklue

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

import os

content = input('请输入需要搜索的关键字')

dirs = [x for x in os.listdir('.') if os.path.isdir(x)]

bedir = os.path.abspath('.')

def find_file(dd):

    cc = os.path.join(bedir, dd)

    os.chdir(cc)

    dir_name = os.listdir('.')

    for x in dir_name:

        if os.path.isfile(x) and os.path.splitext(x)[1] == content:

            print(x, os.path.abspath('.'))

for each in dirs:

    find_file(each)


  • 1

Reply