首页 > 解决方案 > 这个脚本总是返回未知数。即使我的根文件夹中有文件和目录?

问题描述

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")

标签: pythonscripting

解决方案


你的条件不对,你想做:

if os.path.isfile('/root/' + item):

推荐阅读