An error will occur if the directory exists when the directory is created.
FileExistsError: [WinError 183]You cannot create a file that already exists.
import os
DIR_NAME = 'dirname'
if not os.path.exists(DIR_NAME):
os.mkdir(DIR_NAME)
import os
DIR_NAME = 'dirname'
try:
os.mkdir(DIR_NAME)
except OSError as ex:
print(ex)
Recommended Posts