Pathlib mkdir (makedir)



examples/pathlib/path_lib_mkdir.py
from pathlib import Path

folder = Path("abc")
folder.mkdir()       # Creates "abc", fails if it already exists


Path("something").joinpath("else").mkdir(parents=True, exist_ok=True)
# partnes - create intermediate folders as well
# exist_ok - don't fail if folder already exists

examples/pathlib/path_lib_joinpath.py
from pathlib import Path


folder = Path("/")
print(folder)                         # /

subfolder = folder.joinpath("etc")
print(subfolder)                      # /etc

file1 = subfolder.joinpath("a.txt")
print(file1)                          # /etc/a.txt

file2 = subfolder / "b.txt"
print(file2)                          # /etc/b.txt