By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,584 Members | 1,760 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,584 IT Pros & Developers. It's quick & easy.

copying a file in the python script

P: n/a
hi
I am having a problem. I want to copy a file from the folder and
paste it or move it to another folder. Is it possible in python?
Actually I need to implement this in the zope for my site. When I click
any file it should move or copied to another folder in the same machine
using zope.

Thanks in advance.

Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Raghul a écrit :
hi
I am having a problem. I want to copy a file from the folder and
paste it or move it to another folder. Is it possible in python?
Actually I need to implement this in the zope for my site. When I click
any file it should move or copied to another folder in the same machine
using zope.

Thanks in advance.

Hello.

try this :

import shutil
shutil.copyfile(srcfile, dstfile)

if you want to move, just use this after
import os
os.remove(srcfile)

Bye
Fouff
Jul 18 '05 #2

P: n/a
If you are moving the file to another directory on the same hard
drive (e.g. same filesystem) you can use os.rename(old, new) and
the file doesn't have to be copied at all. This is more efficient.
If you are copying to another filesystem, you must use shutil.copy
and os.remove (or os.unlink).

Larry Bates
Raghul wrote:
hi
I am having a problem. I want to copy a file from the folder and
paste it or move it to another folder. Is it possible in python?
Actually I need to implement this in the zope for my site. When I click
any file it should move or copied to another folder in the same machine
using zope.

Thanks in advance.

Jul 18 '05 #3

P: n/a
Larry Bates wrote:
If you are moving the file to another directory on the same hard
drive (e.g. same filesystem) you can use os.rename(old, new) and
the file doesn't have to be copied at all. This is more efficient.
If you are copying to another filesystem, you must use shutil.copy
and os.remove (or os.unlink).


Or use shutil.move() which implements the strategy you describe.

Peter

Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.