rich/examples/cp_progress.py

20 lines
571 B
Python
Raw Permalink Normal View History

"""
A very minimal `cp` clone that displays a progress bar.
"""
import os
import shutil
import sys
2022-04-01 13:17:21 +00:00
from rich.progress import Progress
if __name__ == "__main__":
if len(sys.argv) == 3:
2022-04-01 13:17:21 +00:00
with Progress() as progress:
desc = os.path.basename(sys.argv[1])
2022-04-01 13:17:21 +00:00
with progress.open(sys.argv[1], "rb", description=desc) as src:
with open(sys.argv[2], "wb") as dst:
shutil.copyfileobj(src, dst)
else:
2022-04-01 13:17:21 +00:00
print("Copy a file with a progress bar.")
print("Usage:\n\tpython cp_progress.py SRC DST")