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

shutil.copystat

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


Import

import shutil
from shutil import copystat

Signature & Overview

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

Copy file metadata Copy the permission bits, last access time, last modification time, and flags from src to dst. On Linux, copystat() also copies the "extended

Usage

from pathlib import Path
import shutil
import tempfile

with tempfile.TemporaryDirectory() as tmp:
    a, b = Path(tmp) / "a.txt", Path(tmp) / "b.txt"
    a.write_text("one"); b.write_text("two")
    shutil.copystat(a, b)
    assert int(a.stat().st_mtime) == int(b.stat().st_mtime)

Gotchas

REPL Inspect

from shutil import copystat
help(copystat)

Linked from

Related notes