def renames(old, new):<EOL>
<EOL>head, tail = os.path.split(new)<EOL>if head and tail and not os.path.exists(head):<EOL><INDENT>os.makedirs(head)<EOL><DEDENT>shutil.move(old, new)<EOL>head, tail = os.path.split(old)<EOL>if head and tail:<EOL><INDENT>try:<EOL><INDENT>os.removedirs(head)<EOL><DEDENT>except OSError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>
Like os.renames(), but handles renaming across devices.