how to create a new folder python code example
Example 1: python create directory
import os
os.mkdir('tempDir')
os.mkdir('tempDir2/temp2/temp')
os.makedirs('tempDir2/temp2/temp')
Example 2: creating a new folder in python
newpath = r'C:\Program Files\arbitrary'
if not os.path.exists(newpath):
os.makedirs(newpath)
Example 3: how to add directory to python script
from pathlib import Path
basepath = Path('my_directory/')
files_in_basepath = basepath.iterdir()
for item in files_in_basepath:
if item.is_file():
print(item.name)