I want to use tqdm to display a progress bar when copying a single large file from one filepath to another.
This is not the same as showing a progress bar when copying multiple small files.
I want to use tqdm to display a progress bar when copying a single large file from one filepath to another.
This is not the same as showing a progress bar when copying multiple small files.
Strategy:
Determine the length of the file first so that you can tell tqdm what it is.
Normally then you'd use shutil.copyfile (or shutil.copyfileobj) to actually copy the file but neither of those functions provide a way to receive updates during the copy, which we need to forward to tqdm:
copyfileobjwhich supports passing an update function which is called regularly during copying.updatemethod as the update function to the newcopyfileobjso that it gets called regularly during the copy.Code: