上代码:
import os
# 设置要遍历的文件夹路径
folder_path = 'utils'
# 遍历文件夹
for dirname, subdirs, files in os.walk(folder_path):
print(f'Found directory: {dirname}')
for file in files:
print(f'{os.path.join(dirname, file)} is a file')
# 如果需要遍历子文件夹,上面的代码已经处理了
效果: