如何获得循环阅读子目录并列出文件,然后返回到我正在工作的目录并列出其中的文件中的文件?
我正在尝试找出如何在子目录中列出文件的返回到我正在工作的目录并继续查找文件
#!home/usr/env Python3中 的文件 导入操作系统 文件= [] pather = os.path 尽管 : 对于os.listdir()中的文件: 如果文件==“ for.py”或file.startswith(“。”): 继续 files.append(文件) 而OS.Path.isdir(file)==“ true”: OS.CHDIR(文件) 如果OS.Pathifile(文件): files.append(file)
print(files),
这是我到目前为止的代码,
如果您可以提供帮助,那真是太棒了
I'm trying to find out how to list files in a subdirectory the return to the directory I was working in and continue finding files
#!home/usr/env python3
import os
files = []
pather = os.path
while :
for file in os.listdir():
if file == "for.py" or file.startswith("."):
continue
files.append(file)
while os.path.isdir(file) == "True":
os.chdir(file)
if os.pathisfile(file):
files.append(file)
print(files)
That's my code so far
If you could please help that would be amazing
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这应该有效:
This should work: