On Sat, Sep 17, 2011 at 9:58 AM, Lee Harr <miss...@hotmail.com> wrote: > > I just got a bug report the heart of which is the > difference between unix and windows in using > os.rename > > (ie, "On Windows, if dst already exists, OSError will be raised") > > Hmm, I thought, maybe I'm supposed to use > shutil here. That is the "high-level" operations. > Unfortunately, shutil.move says it depends on > os.rename > > So, what is the best way to do this that will > behave the same across operating systems?
shutil.move works for me, at least in Python 2.7. The docstring doesn't seem to match the code here: try: os.rename(src, real_dst) except OSError: if os.path.isdir(src): if _destinsrc(src, dst): raise Error, "Cannot move a directory '%s' into itself '%s'." % (src, dst) copytree(src, real_dst, symlinks=True) rmtree(src) else: copy2(src, real_dst) os.unlink(src) -- http://mail.python.org/mailman/listinfo/python-list