You did:
with open(cf,"rb") as fl:
for l in fl.read():
l.rstrip()
That is, open the file for binary reading, read all the content with fl.read()
and runs byte by byte by performing the rstrip()
in each byte. That doesn’t even make sense anymore. Why run byte to byte of the file and yet run a rstrip
in it?
And when you do:
with open(ds,"wb") as rw:
rw.write(l)
You will write only the last byte of the read file, which will not be a valid file - indicating that it is corrupted.
What you need to do is:
with open(cf, 'rb') as entrada:
with open(ds, 'wb') as saida:
saida.write(entrada.read())
Or even (Python 2.7+):
with open(cf, 'rb') as entrada, open(ds, 'wb') as saida:
saida.write(entrada.read())
But why reinvent the wheel? Use shutil.copyfile
:
from shutil import copyfile
copyfile(cf, ds)
You can post the code directly to the question. The site has support for such.
– Woss
tried using the tag code but got messy along with the rest of the question
– open software
If you want to put the code in the question copy and paste then have a button in the question edition that allows you to ident the code...
– Maurício Z.B