Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python delete directory if exists

import os
import shutil

dirpath = os.path.join('dataset3', 'dataset')
if os.path.exists(dirpath) and os.path.isdir(dirpath):
    shutil.rmtree(dirpath)
Comment

delete directory if exists python

os.remove() is to remove a file.

os.rmdir() is to remove an empty directory.

shutil.rmtree() is to delete a directory and all its contents.
	shutil.rmtree(dirpath)
Comment

PREVIOUS NEXT
Code Example
Python :: incognito in selenium 
Python :: python add legend title 
Python :: python flask access-control-allow-origin 
Python :: generate a list of numbers upto n 
Python :: dictionary from two lists 
Python :: how to make print float value without scientific notation in dataframe in jupyter notebook 
Python :: txt to list python 
Python :: plot image without axes python 
Python :: shutdown/restart windows with python 
Python :: selenium full screen python 
Python :: loop through list backwards python 
Python :: flask delete cookie stackoverflow 
Python :: load model tensorflow 
Python :: matplotlib text too small 
Python :: df iterrows pandas 
Python :: factorial sequence code in python with while loops 
Python :: read .dat python 
Python :: hide root window tkinter 
Python :: animations text terminal python 
Python :: python press key to break 
Python :: how to add a image in tkinter 
Python :: check numpy version 
Python :: hwo to separate datetime column into date and time pandas 
Python :: how to get just the filename in python 
Python :: pip code for pytube 
Python :: tkiner border 
Python :: python auto module installer 
Python :: pandas save without index 
Python :: how to find the most frequent value in a column in pandas dataframe 
Python :: python join array of ints 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =