from platform import python_version
python_version()
'3.6.9'
import os
import shutil
new_directory_path = "/path/to/new/directory"
if not os.path.exists(new_directory_path):
os.mkdir(new_directory_path)
new_directory_path = "/path/to/new/directory"
if not os.path.exists(new_directory_path):
os.makedirs(new_directory_path)
Including subdirectories, if they exist!
foo
└── bar
├── baz
│ └── some-other-file.txt
└── some-file.txt
import shutil
directory_path_to_remove = "/path/to/foo/"
if os.path.exists(directory_path_to_remove):
shutil.rmtree(directory_path_to_remove)