python how to create a new folder 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: creating a new folder in python
newpath = r'C:\Program Files\arbitrary'
if not os.path.exists(newpath):
os.makedirs(newpath)