From: ivnowa at hvision.nl (Hans Nowak)
Date: Sun, 11 Apr 1999 20:37:07 GMT
Subject: best way to copy a file [Q]
In-Reply-To: <000201be8441$7965d4d0$6eba0ac8@kuarajy.infosys.com.ar>
References: <000201be8441$7965d4d0$6eba0ac8@kuarajy.infosys.com.ar>
Message-ID: <199904111935.VAA24485@axil.hvision.nl>
Content-Length: 1059
X-UID: 785                                                  

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!




