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

shutil.move

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


Import

import shutil
from shutil import move

Signature & Overview

shutil.move(src, dst, copy_function=<function copy2 at 0x1093e0510>)

Recursively move a file or directory to another location. This is similar to the Unix "mv" command. Return the file or directory's destination.

Usage

from pathlib import Path
import shutil
import tempfile

with tempfile.TemporaryDirectory() as tmp:
    src = Path(tmp) / "old.txt"
    dst = Path(tmp) / "new.txt"
    src.write_text("moved", encoding="utf-8")

    shutil.move(src, dst)
    assert not src.exists() and dst.read_text(encoding="utf-8") == "moved"

Gotchas

REPL Inspect

from shutil import move
help(move)

Linked from

Related notes