Python Check If Directory Exists And Create

[Solved] Python Check If Directory Exists And Create | Php - Code Explorer | yomemimo.com
Question : python check if path does not exist

Answered by : nice-newt-l4zhl7y4dx1g

import os
if not os.path.exists('my_folder'):
    os.makedirs('my_folder')

Source : https://www.tutorialspoint.com/How-can-I-create-a-directory-if-it-does-not-exist-using-Python | Last Update : Fri, 17 Apr 20

Question : python check if directory exists and create

Answered by : exuberant-elk-01o520x4uk19

if not os.path.exists('my_folder'): os.makedirs('my_folder')

Source : | Last Update : Wed, 28 Jul 21

Question : create directory python if not exist

Answered by : jocelyn

#From version 3.4, the Python language can natively manage this case.
#The makedirs() function accepts a second parameter, exist_ok.
#By setting the value to true, the method will not throw an exception
# if the directory already exists
os.makedirs(repertoire, exist_ok=True)
#other method
if not os.path.exists(repertoire):	os.makedirs(repertoire)
#other method
try:	os.makedirs(repertoire)
except OSError:	if not os.path.isdir(repertoire):	Raise

Source : | Last Update : Wed, 13 Apr 22

Question : python check if dir exists else create

Answered by :

from pathlib import Path
Path("/my/directory").mkdir(parents=True, exist_ok=True)

Source : https://stackoverflow.com/questions/273192/how-can-i-safely-create-a-nested-directory-in-python/14364249#14364249 | Last Update : Mon, 21 Jun 21

Answers related to python check if directory exists and create

Code Explorer Popular Question For Php