python遍历某个文件夹所有子文件夹

来着网络,记录

import os

path = r'D:\API_AUTO\API_AUTO\test_result'


def get_filelist():

    Filelist = []

    for home, dirs, files in os.walk(path):

        for filename in files:

            # 文件名列表,包含完整路径

            Filelist.append(os.path.join(home, filename))

            # # 文件名列表,只包含文件名

            # Filelist.append( filename)

    return Filelist

if __name__ == "__main__":

    Filelist = get_filelist()

    print(len(Filelist))

    for file in Filelist:

        print(file)

 

posted @ 2021-04-01 15:19  杰的小恒星  阅读(313)  评论(0编辑  收藏  举报