python delete directory if exists

79

python dlete folder -

import shutil

shutil.rmtree('/folder_name')

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)

Comments

Submit
0 Comments