Discuss / Python / 递归函数真的厉害,我自己写的代码我看不懂!!!

递归函数真的厉害,我自己写的代码我看不懂!!!

Topic source
import os

def search_dir_file(keyword,path = '.'):
    '''
    这个文件是为了找出现在目录以及子目录下的一个文件
        keyword:是这个文件包含的关键字
        返回值 是这个文件的 名字 和 路径
        '''
    for x in os.listdir(os.path.abspath(path)):
        if keyword in x:
            print(os.path.join(path,x))
        else:
            b_path =os.path.join(os.path.abspath(path),x)
            if os.path.isdir(b_path):
                search_dir_file(keyword,b_path)

哇哇哇诶

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

应该把 if keyword in x: 改成 if keyword in os.path.splitext(x)[0]:


  • 1

Reply