python - 这个脚本总是返回未知数。即使我的根文件夹中有文件和目录?
问题描述
for item in os.listdir("/root"):
if os.path.isfile(item):
print(item + "is a file")
elif os.path.isdir(item):
print(item + "is a dir")
else:
print("Unknown")
解决方案
你的条件不对,你想做:
if os.path.isfile('/root/' + item):
推荐阅读
- android-constraintlayout - MotionLayout 多状态转换不流畅
- angular - 使用反应式formarray进行角度材料表排序
- vue.js - 如何使每个选择的标签在 vue-multiselect 中唯一
- android - 如何在 Flutter 中的 DraggableScrollableSheet 中实现可滚动的 WebView?
- python - 带有标签的 tkinter 破坏方法存在问题
- c - 使用堆工作的优先级队列,除了 freeC
- reactjs - 使用 useState 为多个值反应表单
- c++ - 全局标量变量(指针)的生命周期
- javascript - 尝试使用引导程序中的 javascript 文件时出现 404 Not found 错误
- c# - ASP.NET 中的 Json 解析