0

i want to copy and paste a file into a directory so i use shutil library in python

file_path = 'C:/Users/user/Downloads/Telegram Desktop/speech.py'
target_path = 'C:/Users/user/Desktop/'
shutil.copyfile(file_path,target_path)

then i got that error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\Python39\lib\shutil.py", line 264, in copyfile
    with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: 'C:/Users/user/Desktop'

how can i fix this?

1
  • try running cmd as admin and then run this code, otherwise You may handle it using try/except, but then still You won't be able to do anything to the file, it just won't throw an error and stop Your code (also when using try/except either except the specific error or print out the exception to know what happened, DO NOT USE bare except: (suggestion)) Commented Jul 17, 2021 at 17:52

1 Answer 1

2

You need to provide the full path to the copy destination, not just to the destination directory

target_path = 'C:/Users/user/Desktop/speech.py'
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.