我们先使用如下代码:

import os

path = 'Path_file'
for i in os.walk(path):
    print(i)
# ("当前文件夹的地址", "当前文件夹下的文件夹名称", "当前文件夹下的文件,不包含子目录文件")

获得的输出结果:

('Path_file', ['Tester_walk02', 'Tester_walk01', 'detail_file'], ['I_Have_a_Dream.txt'])
('Path_file/Tester_walk02', [], ['Tester_walk02_I_Have_a_Dream.txt'])
('Path_file/Tester_walk01', [], ['Tester_walk01_I_Have_a_Dream.txt'])
('Path_file/detail_file', [], ['Path_file_detail_file_I_Have_a_Dream.txt'])

在这里插入图片描述

AI悦创·创造不同!
AI悦创 » Python os.walk() 笔记

发表评论