2014-02-12 60 views
0

我已經得到了壁紙切換工作,但無論什麼原因shutil.copy將無法正常工作。該計劃應爲弱者的每一天設置不同的壁紙。我相信文件路徑是正確的。這個簡單的python程序有什麼問題? shutil錯誤

import time; 
import shutil; 
import ctypes; 
SPI_SETDESKWALLPAPER = 20 

localtime = time.localtime(time.time()) 
wkd = localtime[6] 

if wkd == 6: 
    ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER,0,r"C:\Users\Owner\Documents\Wallpaper\1.jpg",0) 
    shutil.copy(r"C:\Users\Owner\Documents\Wallpaper\1\backgrounddefault.jpg",r"C:\Windows\System32\oobe\INFO\backgrounds") 

elif wkd == 0: 
    ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER,0,r"C:\Users\Owner\Documents\Wallpaper\2.jpg",0) 
    shutil.copy(r"C:\Users\Owner\Documents\Wallpaper\2\backgrounddefault.jpg",r"C:\Windows\System32\oobe\INFO\backgrounds") 

elif wkd == 1: 
    src = r"C:\Users\Owner\Documents\Wallpaper\3\backgrounddefault.jpg" 
    dst = r"C:\Windows\System32\oobe\INFO\backgrounds" 
    ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER,0,r"C:\Users\Owner\Documents\Wallpaper\3.jpg",0) 
    shutil.copy2(src,dst) 

elif wkd == 2: 
    ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER,0,r"C:\Users\Owner\Documents\Wallpaper\4.jpg",0) 
    shutil.copy(r"C:\Users\Owner\Documents\Wallpaper\4\backgrounddefault.jpg",r"C:\Windows\System32\oobe\INFO\backgrounds") 

elif wkd == 3: 
    ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER,0,r"C:\Users\Owner\Documents\Wallpaper\5.jpg",0) 
    shutil.copy(r"C:\Users\Owner\Documents\Wallpaper\5\backgrounddefault.jpg",r"C:\Windows\System32\oobe\INFO\backgrounds") 

elif wkd == 4: 
    ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER,0,r"C:\Users\Owner\Documents\Wallpaper\6.jpg",0) 
    shutil.copy(r"C:\Users\Owner\Documents\Wallpaper\6\backgrounddefault.jpg",r"C:\Windows\System32\oobe\INFO\backgrounds") 

elif wkd == 5: 
    ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER,0,r"C:\Users\Owner\Documents\Wallpaper\7.jpg",0) 
    shutil.copy(r"C:\Users\Owner\Documents\Wallpaper\7\backgrounddefault.jpg",r"C:\Windows\System32\oobe\INFO\backgrounds") 

我收到以下錯誤信息:

Traceback (most recent call last): 
    File "C:\Users\Owner\Documents\Wallpaper\Program.py", line 21, in <module> 
    shutil.copy2(src,dst) 
    File "C:\Python33\lib\shutil.py", line 243, in copy2 
    copyfile(src, dst, follow_symlinks=follow_symlinks) 
    File "C:\Python33\lib\shutil.py", line 110, in copyfile 
    with open(dst, 'wb') as fdst: 
PermissionError: [Errno 13] Permission denied: 'C:\\Windows\\System32\\oobe\\INFO\\backgrounds\\backgrounddefault.jpg' 
+0

權限被拒絕:以管理員身份運行。 –

+0

@SlaterTyranus如何? – user3299467

回答

1

你運行你的代碼作爲用戶是不是有所有系統權利的方式。因此,您需要將您的代碼作爲管理員用戶,它們具有根權限系統的所有權利。

代碼和我的結局一樣好。