🔵 🔵 🔵


Primary

၊၊||၊|။

shutil.move() ⚬|Documentation|1st|20260122195929-00-⌔

shutil — High-level file operations — Python 3.14.2 documentation#shutil.move

shutil.move(src, dst, copy_function=copy2)

Recursively move a file or directory (src) to another location and return the 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 internally when src and the destination are on the same filesystem. In case os.rename() fails due to OSError (e.g. the user has write permission to the destination file but not to its parent directory), this method falls back to using copy_function, in which case src is copied to the destination using copy_function and then removed.

In case of symlinks, a new symlink pointing to the target of src will be created in or as the destination, and src will be removed.

If copy_function is given, it must be a callable that takes two arguments, src and the destination, and will be used to copy src to the destination if os.rename() cannot be used. If the source is a directory, copytree() is called, passing it the copy_function. The default copy_function is copy2(). Using copy() as the copy_function allows the move to succeed when it is not possible to also copy the metadata, at the expense of not copying any of the metadata.

Raises an auditing event shutil.move with arguments src, dst.

Changed in version 3.3: Added explicit symlink handling for foreign filesystems, thus adapting it to the behavior of GNU’s mv. Now returns dst.

Changed in version 3.5: Added the copy_function keyword argument.

Changed in version 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.

Changed in version 3.9: Accepts a path-like object for both src and dst.

Printed 2026-06-28.

(echo:: @ )

Link to original

Secondary

• • •