Odd wording it docs for shutil.move?

eryk sun eryksun at gmail.com
Fri Mar 3 16:05:46 EST 2017


On Fri, Mar 3, 2017 at 5:13 PM, Grant Edwards <grant.b.edwards at gmail.com> wrote:
> At https://docs.python.org/2/library/shutil.html it says:
>
>  shutil.move(src, dst)
>
>     Recursively move a file or directory (src) to another location
>     (dst).
>
>     [...]
>
>     If the destination is on the current filesystem, then os.rename()
>     is used. Otherwise, src is copied (using shutil.copy2()) to dst
>     and then removed.
>
> What does the current filesystem have to do with anything?
>
> Surely, what matters is whether <src> and <dst> are on the same
> filesystem?

The source filesystem was probably the current filesystem in the OP's
thinking, in which case it made sense at the time of writing. Open an
issue if you want to improve the docs with better phrasing.

In Python 2 on Windows, os.rename can move a file across filesystems,
but this is no longer the case in 3.3+ on Windows. Also, os.rename
never replaces an existing file on Windows. (shutil.move should be
using os.replace in Python 3.) It would be more accurate in general if
the shutil.move docs stated only that os.rename is used if the
operation is allowed.


More information about the Python-list mailing list