import os
import os.path
A_server_photo_folder = 'C:/picture' #文件夹路径
def depth_first(path): # 深度优先遍历文件夹,栈,先进后出,先找到最深的,再弹出来,消耗内存
for i in os.listdir(path):
child = os.path.join(path, i)
if os.path.isdir(child):
depth_first(child)
else:
print(child)
depth_first(A_server_photo_folder)
Python 遍历文件夹中的所有文件,并打印所在的路径
最新推荐文章于 2024-07-15 20:56:18 发布
本文介绍了如何使用Python的os和os.path模块实现深度优先遍历文件夹的功能,通过递归调用`depth_first`函数,从给定路径`A_server_photo_folder`开始,打印出所有子目录和非目录文件。
摘要由CSDN通过智能技术生成