Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要用某个目录中的结构填充一个txt,我读取了目录中的文件:
os.listdir(r)
但是,如果一个项目是一个目录,我需要搜索它,知道吗?
使用os.walk. 它将递归遍历路径。前任:
os.walk
import os for root, dirs, files in os.walk(top, topdown=False): for name in files: print(os.path.join(root, name))
您可以使用os.walk.
for root,dirs,files in os.walk(directory): ...