user1179027
user1179027

Reputation: 59

Python script to copy files

I am trying to write a Python script that will copy files from one user’s home directory into another user’s home directory. I want it to copy the permissions, as well. I read the Python API and I think that the copy2 method does just that. However, when I run the following code, I get errors.

import shutil

src = raw_input("Please enter a source: ")
dst = raw_input("Please enter a destination: ")
shutil.copy2(src, dst)

The error says:

Traceback (most recent call last):
  File "copyfiles.py", line 5, in <module>
    shutil.copy2(src, dst)
  File "/usr/lib/python2.6/shutil.py", line 99, in copy2
    copyfile(src, dst)
  File "/usr/lib/python2.6/shutil.py", line 52, in copyfile
    fsrc = open(src, 'rb')
IOError: [Errno 2] No such file or directory: '../../../../Desktop/byteswap.c'

Upvotes: 2

Views: 3423

Answers (1)

Bite code
Bite code

Reputation: 597501

Check your current directory using os.getcwd().

Upvotes: 2

Related Questions