45 lines
1.4 KiB
Plaintext
45 lines
1.4 KiB
Plaintext
From: tim_one at email.msn.com (Tim Peters)
|
|
Date: Sun, 11 Apr 1999 19:45: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: <000901be8453$cd7e21a0$2a9e2299@tim>
|
|
Content-Length: 1051
|
|
X-UID: 1700
|
|
|
|
[Bruno Mattarollo]
|
|
> 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 file ... How can I do a 'copy'
|
|
> ...? I need to run this on NT ...:(
|
|
|
|
If it's to run only under Windows systems, will go fastest to build up an
|
|
xcopy command line and pass it to os.system.
|
|
|
|
> And I don't want to open a shell to do a copy from there... I also tryied
|
|
> fd.read() ... No success neither.
|
|
|
|
Oh sure -- that works fine. The raw "no success" conveys no information,
|
|
though, so not enough clues to guess what part you didn't get right. The
|
|
most common cause for screwing this up is forgetting to open Windows files
|
|
in binary mode.
|
|
|
|
To see how it's done, look at the source code for shutil.py in your Python's
|
|
Lib directory. shutil.copyfile is what you're looking for, if you need a
|
|
cross-platform function.
|
|
|
|
all-obvious-to-everyone-who-already-knows-it<wink>-ly y'rs - tim
|
|
|
|
|
|
|
|
|
|
|
|
|