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 :: django updated_at field 
Python :: integer colomn to datetime pandas 
Python :: get sum from x to y in python 
Python :: set background colour tkinter 
Python :: pandas duplicated rows count 
Python :: is everything in python an object 
Python :: how to catch ctrl c in python 
Python :: Python Removing Directory or File 
Python :: add two datetime python 
Python :: convert numpy array to tensor 
Python :: get rid of unnamed column pandas 
Python :: remove character from string by index in python 
Python :: python returen Thread 
Python :: python opencv draw rectangle with mouse 
Python :: convert dict to string python 
Python :: how to clear the screen of the terminal using python os 
Python :: Read all the lines as a list in a file using the readlines() function 
Python :: pandas front fill 
Python :: excel get unique values from column formula 
Python :: how to take input complex number in python 
Python :: python display name plot 
Python :: application/x-www-form-urlencoded python 
Python :: csv module remove header title python 
Python :: generate list of consecutive numbers 
Python :: Save a Dictionary to File in Python Using the dump Function of the pickle Module 
Python :: discord.py fetch channel 
Python :: groupby count pandas 
Python :: create a generator from a list 
Python :: dataframe add row 
Python :: kafka get last offset of topic python 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =