from pathlib import Path
target_dir = r"D:"
chunk_mb=100
target = Path(target_dir)
target.mkdir(parents=True, exist_ok=True)
chunk = b"\0" * (chunk_mb * 1024 * 1024)
i = 0
written_bytes = 0
next_report = 1 * 1024**3
while True:
path = target / f"fill_{i:06d}.bin"
if path.exists():
i+=1
continue
try:
with path.open("wb") as f:
f.write(chunk)
written_bytes += len(chunk)
if written_bytes >= next_report:
total, used, free = shutil.disk_usage(path)
print(f"{written_bytes // 1024**3} GB written free={free/1024**3:.2f} GB")
next_report += 1 * 1024**3
except OSError as e:
print(f"停止: {e}")
break
i += 1