Skip to content

Instantly share code, notes, and snippets.

@paulgessinger
Created July 3, 2025 08:06
Show Gist options
  • Save paulgessinger/e2ceb7fc9547ffc2a7fb41c5d9ba0e3a to your computer and use it in GitHub Desktop.
Save paulgessinger/e2ceb7fc9547ffc2a7fb41c5d9ba0e3a to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# /// script
# dependencies = [
# "typer",
# "rich",
# ]
# ///
import typer
from typing import Annotated
from pathlib import Path
import shutil
import math
from rich.progress import Progress, MofNCompleteColumn, SpinnerColumn
def main(output_dir: Path, files: list[Path], pattern: str | None = None):
pad = math.floor(math.log10(len(files))) + 1
print(pad)
prog = Progress(
SpinnerColumn(), *Progress.get_default_columns(), MofNCompleteColumn()
)
output_dir.mkdir(exist_ok=True)
with prog:
for i, file in prog.track(
enumerate(files), description="Copying", total=len(files)
):
if pattern is not None:
target_name = pattern.format(i)
else:
target_name = f"{file.stem}_{i:>0{pad}d}{file.suffix}"
target_path = output_dir / target_name
shutil.copyfile(file, target_path)
if __name__ == "__main__":
typer.run(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment