objectif
Mesurer l’espace disque d’un chemin donné.
code minimal
import shutil, pathlib
total, used, free = shutil.disk_usage(pathlib.Path(".").resolve())
print(total > 0 and free >= 0) # attendu: True
utilisation
import shutil, tempfile, pathlib
with tempfile.TemporaryDirectory() as tmp:
t,u,f = shutil.disk_usage(tmp)
print(t >= u >= 0 and f >= 0)
variante(s) utile(s)
import shutil
print(callable(shutil.disk_usage))
notes
- Les valeurs sont en octets; formatez-les selon besoin.
- Utile pour vérifier un espace minimal avant une opération.