Filesystem and I/O Modules

shutil

Offers higher-level file and directory operations such as copyfile(), copytree(), move() and archive helpers. Copying content does not guarantee preservation of all metadata. Recursive deletion is destructive; constrain paths, review symlink behavior and avoid deleting user-supplied locations blindly.

Formal Syntax & Structure

python syntaxpython
import shutil

Return Value

module

Module namespace available through import; import is a statement, not a value-returning expression.

Working Example

Example Snippetpython
import shutilfrom pathlib import Pathfrom tempfile import TemporaryDirectorywith TemporaryDirectory() as folder:    a, b = Path(folder)/"source", Path(folder)/"backup"    a.write_bytes(b"inventory")    shutil.copyfile(a, b)    print(b.read_bytes())
Python Reference