Mailing List Archive

best way to copy a file [ANSWER]
Thanks Hans. It worked... I didn't used the 'rb' and 'wb' when opening the
files...

I should stop working on sundays ... :-) Well, I should stop working
everyday ;)

/B

Bruno Mattarollo <bruno@gaiasur.com.ar>
... proud to be a PSA member <http://www.python.org/psa>

> -----Original Message-----
> From: Hans Nowak [mailto:ivnowa@hvision.nl]
> Sent: Sunday, April 11, 1999 5:37 PM
> To: Bruno Mattarollo; python-list@cwi.nl
> Subject: Re: best way to copy a file [Q]
>
>
> On 11 Apr 99, Ce'Nedra took her magical amulet and heard Bruno
> Mattarollo say:
>
> >Hi!
> >
> > I need to copy a file (can be binary or ascii) from one
> path to another. I
> >have tryied to do:
> > line = fd.readline()
> > while line:
> > fd2.write(line)
> > line = fd.readline()
> > fd.close()
> > fd2.close()
> >
> > It only works for ascii files ... How can I do a 'copy'
> ...? I need to run
> >this on NT ...:( And I don't want to open a shell to do a copy from
> >there... I also tryied fd.read() ... No success neither.
>
> Sure can:
>
> fin = open("myfile", "rb") # notice the 'rb'
> fout = open("target", "wb") # ...and the 'wb'
> data = fin.read(1000) # or any amount of bytes you want to read
> while data:
> fout.write(data)
> data = fin.read(1000)
> fin.close()
> fout.close()
>
> This should work. For large files, a larger number than 1000 may be
> desirable.
>
> + Hans Nowak (Zephyr Falcon)
> + Homepage (under construction): http://www.cuci.nl/~hnowak/
> + You call me a masterless man. You are wrong. I am my own master.
> + May a plumber throw eggs at your dead presidents!
>