> I'm new to python and I am trying to figure out how to remove all sub > directories from a parent directory using a wildcard. For example, > remove all sub directory folders that contain the word "PEMA" from the > parent directory "C:\Data". > > I've trying to use os.walk with glob, but I'm not sure if this is the > right path to take. > > Thanks for any suggestions!
I think I'd do something like this (untested). import os, shutil startDir = r"C:\Data" for item in os.listdir(startDir): folder = os.path.join(startDir, item) if os.path.isdir(folder) and "PEMA" in item: shutil.rmtree(folder) Cheers, Drea -- http://mail.python.org/mailman/listinfo/python-list