2

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'
1
  • 6
    The error message seems pretty clear: The file ../../../../Desktop/byteswap.c does not exist. Note that the path is relative to the current working directory, so check with print os.getcwd() if it is as expected. Commented Feb 13, 2012 at 16:34

1 Answer 1

2

Check your current directory using os.getcwd().

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.