A python program to check if directory with given name exists, and create if it does not. First thing that we need to do is import module called “os” and use the function inside it to check if the directory exists or not.
__author__ = 'sureshkumarmukhiya' import os def makedir(directory): if not os.path.exists(directory): os.makedirs(directory) print ("New Directory Created with Name, " + directory) else : print (directory + " directory Already Exists!") makedir('images')
If you run this program for the first time, and suppose the images directory does not exists in your current working directory, it will create images folder. And if you run this program again, it will exit with message, “images directory Already Exists!”