python - 如何在python中使用os.walk函数获取完整路径
问题描述
我正在使用 os.walk 查找目录,但它没有显示完整路径
代码:
for root, subdirs, files in os.walk(path):
print(subdirs)
我将系统/值分配给路径。
预期输出:system/a/a
输出:一个
现在我可以使用glob.glob
,但它列出了符号链接,我不想要那个
解决方案
for root, dirnames, fnames in os.walk(path):
print("I am looking in", root)
print("These are the subdirectories:")
for dirname in dirnames:
print(os.path.join(root, dirname))
print("These are the filenames:")
for fname in fnames:
print(os.path.join(root, fname))
推荐阅读
- python - 如何总结列表列表中的元素以在python中进行任意组合
- firebase - Flutter 签名上传到 Firebase 存储
- java - 如何在这种情况下使用对象数组?
- json - Maximo 与外部 JSON API 的集成
- c++ - 将 CMake 配置为在 C++20 中编译,但可执行文件在 C++17 中编译
- rust - 如何将 actix_web HttpServer::new(..) 的参数提取到单独的函数中?
- azure-sql-database - Azure 数据工厂:执行管道活动无法引用调用管道,需要循环行为
- javascript - React Native 获取 https localhost 网络请求失败
- sql - 如何创建一个表,其中 ScheduledDate 下的所有行都是同一日期 9/21/2018?
- android - 重绘部分视图 OnDraw(canvas: Canvas)