On this page
  1. shutil.copy2
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

shutil.copy2

Prev: shutil.copy | Up: shutil | Next: shutil.copyfile
Rel: shutil.chown, shutil.copy, shutil.copyfile, shutil.copyfileobj
Ref: docs.python.org — shutil.copy2
Tags: #public #python3 #stdlib #shutil


Import

import shutil
from shutil import copy2

Signature & Overview

shutil.copy2(src, dst, *, follow_symlinks=True)

Copy data and metadata. Return the file's destination.

Usage

from pathlib import Path
import shutil
import tempfile

with tempfile.TemporaryDirectory() as tmp:
    src = Path(tmp) / "a.txt"
    dst = Path(tmp) / "b.txt"
    src.write_text("data", encoding="utf-8")

    shutil.copy2(src, dst)
    assert int(src.stat().st_mtime) == int(dst.stat().st_mtime)

Gotchas

REPL Inspect

from shutil import copy2
help(copy2)

Linked from

Related notes