PyDocs

Nav

File and Directory Access

move

shutil

function (source)
  • move(src, dst, copy_function=copy2)
Recursively move a file or directory to another location. This is
similar to the Unix "mv" command. Return the file or directory's
destination.

If dst is an existing directory or a symlink to a directory, then src is
moved inside that directory. The destination path in that directory must
not already exist.

If dst already exists but is not a directory, it may be overwritten
depending on os.rename() semantics.

os.rename() is preferably used if the source and destination are on the
same filesystem. In case os.rename() fails due to OSError (e.g. the user
has write permission to *dst* file but not to its parent directory),
this method falls back to using *copy_function* silently.
Symlinks are also recreated under the new name if os.rename() fails
because of cross filesystem renames.

It's recommended to use os.rename() if atomic move is strictly required.

The optional `copy_function` argument is a callable that will be used
to copy the source or it will be delegated to `copytree`.
By default, copy2() is used, but any function that supports the same
signature (like copy()) can be used.

A lot more could be done here...  A look at a mv.c shows a lot of
the issues this implementation glosses over.
Changed in 3.3, 3.5, 3.8, 3.9
  • 3.3: Added explicit symlink handling for foreign filesystems, thus adapting it to the behavior of GNU’s mv. Now returns dst.
  • 3.5: Added the copy_function keyword argument.
  • 3.8: Platform-specific fast-copy syscalls may be used internally in order to copy the file more efficiently. See Platform-dependent efficient copy operations section.
  • 3.9: Accepts a path-like object for both src and dst.
0 Examples
No examples for shutil/move.
See Also
No see-alsos for shutil/move
0 Notes
No notes for move