【发布时间】:2016-12-01 15:07:51
【问题描述】:
我需要编写一个脚本来遍历目录中的所有目录。它应该进入每个目录,获取其名称并将其保存到变量中并返回,然后循环。
for dir in os.walk(exDir):
path = dir
os.chdir(path)
source = #dir trimmed to anything after the last /
os.chdir("..")
loops
它需要进入目录来做上面没有提到的其他事情。我才刚刚开始使用 Python,并且在最后一天左右一直被困在这个问题上。
【问题讨论】:
-
您是否阅读了
os.walk()的文档?它返回一个元组。 docs.python.org/3/library/os.html -
@cdarke 我没有仔细看清楚。谢谢你。
标签: python python-3.x navigation directory