From: brunomadv at ciudad.com.ar (Bruno Mattarollo)
Date: Sun, 11 Apr 1999 19:49:50 GMT
Subject: best way to copy a file [ANSWER]
In-Reply-To: <199904111935.VAA24485@axil.hvision.nl>
References: <199904111935.VAA24485@axil.hvision.nl>
Message-ID: <000801be8454$7608f390$6eba0ac8@kuarajy.infosys.com.ar>
Content-Length: 1613
X-UID: 1277                                                  

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 at gaiasur.com.ar>
... proud to be a PSA member <http://www.python.org/psa>

> -----Original Message-----
> From: Hans Nowak [mailto:ivnowa at hvision.nl]
> Sent: Sunday, April 11, 1999 5:37 PM
> To: Bruno Mattarollo; python-list at 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!
>





