Seite 1 von 1

Moving/Copying files

Verfasst: Mittwoch 26. März 2003, 14:10
von snakey
how do i move files to a specific directory ?

Verfasst: Mittwoch 26. März 2003, 16:00
von ASCII158
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...

Verfasst: Mittwoch 26. März 2003, 16:32
von snakey
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.

Verfasst: Mittwoch 26. März 2003, 16:40
von joerg
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

Verfasst: Donnerstag 27. März 2003, 10:56
von snakey
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 :)

Verfasst: Donnerstag 27. März 2003, 12:02
von joerg
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