You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.7 KiB

From: matt at (Matthew Dixon Cowles)
Date: Sun, 11 Apr 1999 13:59:56 -0500
Subject: best way to copy a file [Q]
References: <000201be8441$7965d4d0$>
Message-ID: <>
Content-Length: 1370
X-UID: 151
In article <000201be8441$7965d4d0$6eba0ac8 at>, "Bruno
Mattarollo" <brunomadv at> wrote:
> 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 ... No success neither. I have looked
> unsuccesfully throughout the documentation and didn't find a 'filecopy'
> method. The files can range from 1KB to 600MB+ ...
You need to open the files in "binary" mode since Windows makes a
distinction between text and binary files. I understand that something
should work. Also, you might want to reconsider using readline() for
binary files. If a large binary file happened not to contain \r\n,
readline() might try to grab an unreasonably large piece of the file:
>>> foo=open("/dev/zero")
>>> foo.readline()
Bus error
The function copyfile() in the standard module shutil would probably work
well for you. But now you know why <wink>.