While @sleeplessnerd's answer may work for os.mkdir()
specifically, there is a better way that seems to be both platform agnostic¹ and requires less overhead than manually mounting it as a drive letter. It uses pathlib.Path()
and the mkdir()
method.
pathlib.Path(r"\\remote\server\path\your_folder").mkdir()
Some useful parameters are parents
, which creates the full file path - every folder in the path - if it doesn't exist and exist_ok=True
, which prevents it from throwing an error if the folder already exists. Some example code:
# if you're making a log directory
LOG_DIR = pathlib.Path(r"\\remote\server\path\logs")
LOG_DIR.mkdir(parents=False, exist_ok=True)
I tested both samples on Python 3.13 64bit and both create an empty folder at the path specified.
¹ I have not tested it on other platforms and as this example uses Windows' file paths, I'm not sure how that would play into remote shares on other operating systems.