Moving/Copying files

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
snakey
User
Beiträge: 3
Registriert: Mittwoch 26. März 2003, 14:05
Wohnort: Köln

how do i move files to a specific directory ?
ASCII158
User
Beiträge: 80
Registriert: Samstag 28. September 2002, 15:40
Wohnort: München

The first way: use the os-specific function "cp" in linux and "copy" in windows.

The other way: open the sourcefile, read the sourcefile, open the target file, write the sourcefile to the targetfile...
mfg,

10011110
snakey
User
Beiträge: 3
Registriert: Mittwoch 26. März 2003, 14:05
Wohnort: Köln

I want to transfer a bunch of files. not just one.
so if i have 10 files in one directory, i want to copy them or move them (after i finish writing to them) to another directory.
joerg
User
Beiträge: 188
Registriert: Samstag 17. August 2002, 17:48
Wohnort: Berlin
Kontaktdaten:

Just have a look at the standard module 'shutil', which provides some convenient functions for this. I'm not sure if this is platform-independent.

Good luck
Jörg
snakey
User
Beiträge: 3
Registriert: Mittwoch 26. März 2003, 14:05
Wohnort: Köln

Now what i have is,
in the directory c:\temp , i have 10 txt files
and i want to move them to d:\temp

with shutil i tried

copyfile('c:\temp\*.txt' ,''d:\temp\')

is this valid ?
Excuse my ignorance, i am new at Python :)
joerg
User
Beiträge: 188
Registriert: Samstag 17. August 2002, 17:48
Wohnort: Berlin
Kontaktdaten:

If you want to use shell patterns you need the module 'glob' too:

Code: Alles auswählen

import shutil, glob
for f in glob.glob(r"c:\ham\*.txt"):
	shutil.copy(f, r"d:\ham\")
This should work, but I didn't test it.

Joerg
Antworten