Created
February 20, 2020 03:51
-
-
Save gargolito/073dead3ed3daac2f93dcdc5d4274f18 to your computer and use it in GitHub Desktop.
python copy file with progress bar in terminal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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