python determines whether a file is a simple instance of a folder

  • 2021-06-28 09:32:53
  • OfStack

As follows:


import os
if os.path.isdir(path):
  print "it's a directory"
elif os.path.isfile(path):
  print "it's a normal file"
else:
  print "it's a special file(socket,FIFO,device file)"

Related articles: