python 3 create multiple directory if not exists code example
Example 1: create a directory python
#creates a directory without throwing an error
import os
def create_dir(dir):
if not os.path.exists(dir):
os.makedirs(dir)
print("Created Directory : ", dir)
else:
print("Directory already existed : ", dir)
return dir
Example 2: create directory in python
import os
directory = "Krishna"
path_dir = "C:/Users/../Desktop/current_dir/"
if not os.path.exists(directory):
os.mkdir(os.path.join(path_dir, directory))