คุณสามารถใช้ฟังก์ชัน os.walk เพื่อเดินผ่านแผนผังไดเร็กทอรีใน python
ตัวอย่าง
import os
for dirpath, dirs, files in os.walk("./my_directory/"):
for filename in files:
fname = os.path.join(dirpath,filename)
with open(fname) as myfile:
print(myfile.read()) โปรแกรมข้างต้นจะย้ายซ้ำผ่านแผนผัง my_directory และพิมพ์เนื้อหาของแต่ละไฟล์ในแผนผังไปยังเอาต์พุตคอนโซล