On this page
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
- Metadata only: Copies permission bits,
atime,mtime, and flags without modifying file contents or ownership.
REPL Inspect
from shutil import copystat
help(copystat)
Linked from
Related notes
- tuts/python3/stdlib_module/shutil/copymode Linked here; links to this page; shared tags: #shutil, #stdlib
- tuts/python3/stdlib_module/shutil/copytree Linked here; links to this page; shared tags: #shutil, #stdlib
- tuts/python3/stdlib_module/shutil Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/shutil/chown Linked here; shared tags: #shutil, #stdlib
- tuts/python3/stdlib_module/shutil/copy Linked here; shared tags: #shutil, #stdlib
- tuts/python3/stdlib_module/shutil/copy2 Linked here; shared tags: #shutil, #stdlib
- tuts/python3/stdlib_module/shutil/copyfile Linked here; shared tags: #shutil, #stdlib
- tuts/python3/stdlib_module/shutil/copyfileobj shared tags: #shutil, #stdlib
- tuts/python3/stdlib_module/shutil/disk_usage shared tags: #shutil, #stdlib
- tuts/python3/stdlib_module/shutil/Error shared tags: #shutil, #stdlib