Reputation: 85
I would like to delete all folders/directories with a common prefix name. How can this be achieved in python ?
example : all folders with names with prefix - 'reports_'
Upvotes: 0
Views: 2145
Reputation: 819
this is the simplest solution that I could think of to solve your problem.
import shutil
import glob
import os
base_path = ""
dir_list = glob.iglob(os.path.join(base_path, "reports_*"))
for path in dir_list:
if os.path.isdir(path):
shutil.rmtree(path)
Upvotes: 5