import os
import shutil
dirpath = os.path.join('dataset3', 'dataset')
if os.path.exists(dirpath) and os.path.isdir(dirpath):
shutil.rmtree(dirpath)
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)