python 2.7 - Using os.listdir(), see if an object is a file or a directory -
here code wrote:
import os item in os.listdir("c:/"): if os.path.isfile(item): print(item + " file") elif os.path.isdir(item): print(item + " dir") else: print("unknown!")
response:
unknown! unknown! unknown! unknown! unknown! unknown! unknown! unknown! unknown! unknown! unknown! unknown! unknown! unknown! unknown! unknown! unknown! unknown! unknown! unknown! unknown! unknown! unknown! unknown! unknown! process finished exit code 0
what did wrong. think maybe because folder locked or encrypted. please give hand!
thanks lot
you need pass complete path isfile()
, isdir()
.
import os path = "c:" item in os.listdir(path): item = os.path.join(path, item) if os.path.isfile(item): print(item + " file") elif os.path.isdir(item): print(item + " dir") else: print("unknown!")
Comments
Post a Comment