python if is a directory code example
Example 1: check dir exist python
import os.path
from os import path
def main():
print ("File exists:"+str(path.exists('guru99.txt')))
print ("File exists:" + str(path.exists('career.guru99.txt')))
print ("directory exists:" + str(path.exists('myDirectory')))
if __name__== "__main__":
main()
Example 2: python os is directory
import os.path
path = '/home/User/Documents/file.txt'
isdir = os.path.isdir(path)
print(isdir)
path = '/home/User/Documents/'
isdir = os.path.isdir(path)
print(isdir)