递归找文件夹

import os

def check_inpath(path, dir):
    path_dir = os.listdir(path)
    for dir_scn in path_dir:
        path_join = os.path.join(path, dir_scn)
        if os.path.isdir(path_join):
            if path_join == os.path.join(path, dir):
                return path_join
            else:
                ret = check_inpath(path_join, dir)
                if ret:return ret

current = r'D:\Python27\Day10\ftp作业3\server'
target = 'ccc'

print(check_inpath(current, target))

  

posted @ 2019-09-18 10:12  流年中渲染了微笑  阅读(62)  评论(0编辑  收藏  举报