python shutil copyfile permission error

8.1k Views Asked by At

I am trying to copy an image from one folder to another folder using shutil in python 3.6 windows 10, but am running into permission errors.

I have my source saved as a variable named 'src' which contains

src = "C:/Users/marti/AppData/Roaming/vlc/art/artistalbum/artistname/art.jpg" 

and my destination named 'src' which contains

dst = "C:/Users/marti/Desktop/MRL/cover"

my file currently imports these things:

from shutil import copyfile
from sys import exit
import os
import requests

and I am copying the src to the destination using this command:

copyfile(src, dst)

But when I run this program I am given a permission error:

IOError: [Errno 13] Permission denied: 'C:/Users/marti/Desktop/MRL/cover/'

even when I'm running CMD as administrator, does anyone know how to edit these permissions for python?

If not I'm open to any other methods which will allow me to copy an image from one folder to another folder, and eventually check if the src string has changed in which case it will delete the image in the dst folder and replace it

2

There are 2 best solutions below

0
On

From the shutil doc:

Copy the contents (no metadata) of the file named src to a file named dst and return dst. src and dst are path names given as strings. dst must be the complete target file name; look at shutil.copy() for a copy that accepts a target directory path. If src and dst specify the same file, SameFileError is raised.

You should pay attention the dst must be the complete target file name.

1
On

I have had similar issue when copying a native file to NAS, but easily solved by replacing shutil.copyfile with shutil.copy.


My previous error messages:

    with open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: