You have all of the pieces: glob()
iterates, and rmtree()
deletes:
for path in glob.glob("directory_*"):
shutil.rmtree(path)
This will throw OSError
if one of the globbed paths names a file, or for any other reason that rmtree()
can fail. You can add error handling as you see fit, once you decide how you want to handle the errors. It doesn't make sense to add error handling unless you know what you want to do with the error, so I have left error handling out.