Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python make directory if not exists

try:
    os.makedirs("path/to/directory")
except FileExistsError:
    # directory already exists
    pass
Comment

create directory python if not exist

#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
Comment

python create folder if not exists

if (not os.path.exists("images")):
    os.mkdir("images")
Comment

PREVIOUS NEXT
Code Example
Python :: ignore warnings 
Python :: python tkinter window fullscreen 
Python :: pandas read tsv 
Python :: how to open a website in python 
Python :: pandas iterrows tqdm 
Python :: if file exists delete python 
Python :: pygame boilerplate 
Python :: matplotlib is required for plotting when the default backend "matplotlib" is selected. 
Python :: python b to string 
Python :: disable images selenium python 
Python :: make jupyter notebook wider 
Python :: save utf 8 text file in python 
Python :: remove column from df 
Python :: delete pycache files 
Python :: python get location of script 
Python :: pygame play sound 
Python :: installing pip 
Python :: pylsp install 
Python :: matplotlib.pyplot imshow size 
Python :: install streamlit 
Python :: use incognito mode in selenium 
Python :: python toast notification 
Python :: python remove non letters from string 
Python :: python iterate list reverse 
Python :: hide window in selenium Webdriver python 
Python :: convert column to numeric pandas 
Python :: create python virtual environment 
Python :: verify django has been installed 
Python :: how to convert datetime to jdatetime 
Python :: Tk.destroy arguments 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =