python 递归迭代目录

  

from pathlib import Path
def openfile(path:str)->None:
    yield path

def cix(path:str):
    p=Path(path)
    if p.exists():
        if p.is_file():
            yield from openfile(str(p))
        elif p.is_dir():
            for item in p.iterdir():
                if item.is_file():
                    yield from openfile(str(item))
                elif item.is_dir():
                    yield from cix(str(item))

for b in cix("d:/wamp"):

posted @ 2020-10-02 12:50  ascertain  阅读(190)  评论(0编辑  收藏  举报