We use pathlib and forward slashes so that the Path() function can be used to automatically convert backslash to forward slash on Linux systems.
Does directory exist?
from pathlib import Path
if not Path('C:/MyDirectoryname').is_dir():
print("Does not exist")
Create Directory
from pathlib import Path
import os
if not Path('C:/MyDirectoryname').is_dir():
os.makedirs('C:/MyDirectoryname')
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.