2017-09-16 207 views
-1

我想從一個文件夾複製圖像到另一個文件夾使用shutil在python 3.6窗口10,但我正在運行許可錯誤。python shutil複製文件權限錯誤

我有我的源代碼保存爲一個名爲「src」中包含

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

和我的名爲「SRC」目的地包含可變

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

我的文件目前進口這些東西:

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

我正在使用此命令將src複製到目標:

copyfile(src, dst) 

但是當我運行這個程序,我給予了權限錯誤:

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

甚至當我運行CMD以管理員身份,沒有人知道如何編輯這些權限蟒蛇?

如果不是,我打開任何其他方法,這將允許我將圖像從一個文件夾複製到另一個文件夾,並最終檢查src字符串是否已更改,在這種情況下,它將刪除dst文件夾中的圖像並更換

+0

我不會,如果它是一個錯字,但你的變量'src'中有空格字符。那麼,'src'中的文件名在哪裏? 'src = r「C:/Users/marti/Desktop/MRL/cover/art.jpg」'可能會更好。 – Kanak

+0

是的,這是一種類型的謝謝,但是當我修復它,並且沒有空格的src時,我仍然得到這個錯誤信息:Traceback(最近調用最後一個): 文件「a.py」,第39行,在 getInfo() 文件「a.py」,第36行,在getInfo中 複製文件(src,dst) 文件「c:\ Python27 \ lib \ shutil.py」,第83行,複製文件 with open(dst,' wb')as fdst: IOError:[Errno 13] Permission denied:'C:/ Users/marti/Desktop/MRL/cover' – Martin

+0

@MartinBarker請將信息發佈到您的問題,我們不知道temp_loc是這裏有什麼。你可以解釋嗎 ? – aircraft

回答

0

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.

你要注意的dst must be the complete target file name