Answers for "delete directory if exists python"

0

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)
Posted by: Guest on July-20-2021
0

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)
Posted by: Guest on March-16-2022

Code answers related to "delete directory if exists python"

Python Answers by Framework

Browse Popular Code Answers by Language