Átomo
33Pl
Ficheiros e sistema · Python

pathlib.Path

Abrir na tabela

Definição

Caminhos como objetos: juntar partes, ler, escrever, listar e testar existência.

Exemplos

1. Montar caminhos
from pathlib import Path

landing = Path("/landing") / "sales" / "2026"
print(landing.name, landing.suffix, landing.parent)
2. Listar ficheiros
csv_files = sorted(Path("/landing/sales").glob("*.csv"))
all_parquet = list(Path("/lake").rglob("*.parquet"))
3. Ler, escrever e criar pastas
Path("/tmp/out").mkdir(parents=True, exist_ok=True)
Path("/tmp/out/done.txt").write_text("OK")
if Path("config.json").exists():
    text = Path("config.json").read_text()

No mesmo grupo