这个脚本总是返回未知。即使我的根文件夹中有文件和目录?

ris*_*war 3 python scripting

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")
Run Code Online (Sandbox Code Playgroud)

Tho*_*aci 5

你的条件不对,你想做:

if os.path.isfile('/root/' + item):
Run Code Online (Sandbox Code Playgroud)