遍历该目录结构的文件,使用os.walk('a')
import os
for root, dirs, files in os.walk("a", topdown=True):
for name in files:
print(os.path.join(root, name))
输出:a\b\1.py
a\b\2.py
a\b\d\1.py
a\b\d\2.py
a\c\1.py
a\c\2.py
遍历该目录结构的文件,使用os.walk('a')
import os
for root, dirs, files in os.walk("a", topdown=True):
for name in files:
print(os.path.join(root, name))
输出:a\b\1.py
a\b\2.py
a\b\d\1.py
a\b\d\2.py
a\c\1.py
a\c\2.py
本文标题:os
本文链接:https://www.haomeiwen.com/subject/nhnwmxtx.html
网友评论