def try_rename(root, name=None):
    "Try to rename a file or directory."
    if name is None:
        old, new = root, path.join(path.dirname(root), uuid4().hex)
    else:
        old, new = path.join(root, name), path.join(root, uuid4().hex)
    try:
        rename(old, new)
    except EnvironmentError:
        return old
    return new
Try to rename a file or directory.
recipes/Python/577670_Destroying_Directories/recipe-577670.py