Can you make it `os.path.dirname(ipdir)`.  No sense not to do the full-cleanup.