Mailing List Archive

Newbie: easy filecopy?
Sorry,
it's me again.;-)

I couldn't believe it. I think there must be an easy copy-function
in python (I only want to copy files under ext2- or FAT-FileSystems).
Call me "4 blind mice"-Joey, but I couldn't find it.
For sure, I could write a thing like open-read-write-close, but I
think, someone else has done already, hasn't he?

Thanx again for patience with me...[snuff]

Ciao,
Holger
Newbie: easy filecopy? [ In reply to ]
In article <376531D3.7E42AC42@phoenix-edv.netzservice.de>,
Holger Jannsen <holger@phoenix-edv.netzservice.de> wrote:
>
>I couldn't believe it. I think there must be an easy copy-function
>in python (I only want to copy files under ext2- or FAT-FileSystems).
>Call me "4 blind mice"-Joey, but I couldn't find it.
>For sure, I could write a thing like open-read-write-close, but I
>think, someone else has done already, hasn't he?

Look at the shutil module.
--
--- Aahz (@netcom.com)

Hugs and backrubs -- I break Rule 6 <*> http://www.rahul.net/aahz/
Androgynous poly kinky vanilla queer het

"That doesn't stop me from wanting to work all three of them over with
the clue stick for while, with no safewords allowed." --abostick
Newbie: easy filecopy? [ In reply to ]
Another ascpect to my question of yesterday:

The problem with
f=open(aFile)
x=f.read()
f.close
f.open(toFile)
f.write(x)
f.close
is, that some special ASCII-codes are not copied as usual
under Windows-systems, so e.g. CarriageReturn (tested with normal
Asccii-text).

Hints?

Ciao,
Holger

Holger Jannsen schrieb:
>
> Sorry,
> it's me again.;-)
>
> I couldn't believe it. I think there must be an easy copy-function
> in python (I only want to copy files under ext2- or FAT-FileSystems).
> Call me "4 blind mice"-Joey, but I couldn't find it.
> For sure, I could write a thing like open-read-write-close, but I
> think, someone else has done already, hasn't he?
>
> Thanx again for patience with me...[snuff]
>
> Ciao,
> Holger
Newbie: easy filecopy? [ In reply to ]
Holger Jannsen writes:
> I couldn't believe it. I think there must be an easy copy-function
> in python (I only want to copy files under ext2- or FAT-FileSystems).
> Call me "4 blind mice"-Joey, but I couldn't find it.

Yes. As someone has pointed out, the shutil module contains the
beast you're looking for.
The Index of the Library Reference manual is often pretty helpful
about things like this (not the Module Index, the general Index).
Just click on the "i" icon at the top of any page of the library
reference if you're using the HTML version. The index may be long,
but I'm told it isn't too shabby.
(If anyone thinks additional entries are needed, send a note telling
what they are and where they should link to in the manual to
python-docs@python.org; this kind of suggestion is usually well
received by the damn fool^H^H^H^H^H^H^H^H^H^H poor bloke who receives
mail at that address.)


-Fred

--
Fred L. Drake, Jr. <fdrake@acm.org>
Corporation for National Research Initiatives
Newbie: easy filecopy? [ In reply to ]
"Fred L. Drake" wrote:
> As someone has pointed out, the shutil module contains the
> beast you're looking for.

I believe shutil.py is an obscure name for this
particular module. I only discovered it (years ago)
by accident when looking for an example of os.path.walk.

It's probably too late, but it would be great if we
could change the name to filecopy.py, retaining
shutil.py (which could import filecopy's code).

-Jeff
Newbie: easy filecopy? [ In reply to ]
Holger Jannsen writes:

> Another ascpect to my question of yesterday:
>
> The problem with
> f=open(aFile)
> x=f.read()
> f.close
> f.open(toFile)
> f.write(x)
> f.close
> is, that some special ASCII-codes are not copied as usual
> under Windows-systems, so e.g. CarriageReturn (tested with normal
> Asccii-text).

You're doing something funny, but not sure what from your pseudo
code.

open(aFile) is equivalent to open(aFile, 'r'), which is text mode
- it will translate \r\n to \n on input. open(toFile,'w') would also
open text mode, and translate \n to \r\n on ouput. Your symptoms
match reading from a file in text mode, but writing in binary mode
(eg, open(toFile, 'wb')).

Don't worry - you're in good company. Netscape gets them confused
frequently too.

- Gordon
Newbie: easy filecopy? [ In reply to ]
In article <37665D08.267A697C@phoenix-edv.netzservice.de>,
Holger Jannsen <holger@phoenix-edv.netzservice.de> wrote:
>
>The problem with
>f=open(aFile)
>x=f.read()
>f.close
>f.open(toFile)
>f.write(x)
>f.close
>is, that some special ASCII-codes are not copied as usual
>under Windows-systems, so e.g. CarriageReturn (tested with normal
>Asccii-text).

Open the file in binary mode.
--
--- Aahz (@netcom.com)

Hugs and backrubs -- I break Rule 6 <*> http://www.rahul.net/aahz/
Androgynous poly kinky vanilla queer het

"That doesn't stop me from wanting to work all three of them over with
the clue stick for while, with no safewords allowed." --abostick