Answers for "python create directory if non existent"

0

python create directory if non existent

import os
if not os.path.exists('my_folder'):
    os.makedirs('my_folder')
    
#You can also use the python idiom EAFP: 
#Easier to ask for forgiveness than permission. For example,

try:
    os.makedirs('my_folder')
except OSError as e:
    if e.errno != errno.EEXIST:
        raise
Posted by: Guest on April-18-2021

Code answers related to "python create directory if non existent"

Python Answers by Framework

Browse Popular Code Answers by Language