python 获取指定目录下,所有的子文件、子文件夹中的文件

说明

本文介绍 获取指定目录下,所有的子文件、子文件夹中的文件

注意:不要子文件夹

缺点

path.rglob()

from pathlib import Path

path = Path(r"C:\Users\mym\Desktop")
for file in path.rglob("*.*"):
    print(file)

os.walk

import os
path = r"C:\Users\mym\Desktop\重庆发票"
for root,folders,files in os.walk(path):
    for file in files:
        print(os.path.join(root,file))

参考:
https://zhuanlan.zhihu.com/p/609327324


原文出处:/show_1IX7RpNbUG4W.html