Skip to content

Instantly share code, notes, and snippets.

@gargolito
Created February 20, 2020 03:51
Show Gist options
  • Save gargolito/073dead3ed3daac2f93dcdc5d4274f18 to your computer and use it in GitHub Desktop.
Save gargolito/073dead3ed3daac2f93dcdc5d4274f18 to your computer and use it in GitHub Desktop.
python copy file with progress bar in terminal
import os
from io import BytesIO
from tqdm import tqdm
file = 'FILENAME'
fsize = int(os.path.getsize(file))
new = 'NEWFILENAME'
with open(file, 'rb') as f:
with open(new, 'ab') as n:
with tqdm(ncols=60, total=fsize, bar_format='{l_bar}{bar} | Remaining: {remaining}') as pbar:
buffer = bytearray()
while True:
buf = f.read(8192)
n.write(buf)
if len(buf) == 0:
break
buffer += buf
pbar.update(len(buf))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment