Posting this since it's a likely cause of problems like this, if not necessarily in this specific case. Desktop
(along with most other user folders) is a pseudo-magic folder, and you can't rely on it always being found at C:\Users\USERNAME\Desktop
. In particular, just because you see a file on your desktop doesn't mean it's actually there. It could be in the All Users
Desktop
folder, and either of those could be redirected by the Windows Library folder redirection magic.
If you want to get the correct path to the user's desktop dynamically, you can use the pywin32
extension to do so:
from win32com.shell import shell, shellcon
shell.SHGetFolderPath(0, shellcon.CSIDL_MYPICTURES, None, 0)
(hat tip to this answer), or to get the common Desktop
folder for all users:
import win32com.client
objShell = win32com.client.Dispatch("WScript.Shell")
allUserDocs = objShell.SpecialFolders("AllUsersDesktop")
(hat tip to this answer).
Both approaches above might be replaceable on Vista and higher with code that calls SHGetKnownFolderPath
(either with pywin32
if it supports it, or directly through a ctypes
wrapper) using FOLDERID_Desktop
and FOLDERID_PublicDesktop
for the user specific and commonly shared Desktop
folders.