May-22-2018, 04:27 PM
Alright, this is my next version (I'm more happy with it):
But the above code floats my boat, so I'll move on.
import os def copyFunc(source, destination): with open(source, 'rb') as f1, open(destination, 'wb') as f2: full_size = os.stat(source).st_size full = 0 increment = 10485760 chunk = f1.read(increment) while f1.read(increment): full += increment if full + increment > full_size: full += full_size - full f2.write(chunk) print(round(full / full_size * 100, 1), '%\r') one = '397.64-desktop.exe' two = 'C:\\Users\Mark\Downloads\Ordenador\driver.exe' copyFunc(one, two)The changes you made helped me. I didn't fully understand what was happening behind the scenes with
.read()and
.write(). It's good that Python tracks written size vs read size and other stuff pertaining (that I'm not understanding, TBH) to the transfer of file objects. That would be more code if the scripter had to handle him/herself.
But the above code floats my boat, so I'll move on.