Get the desktop folder

Introduction

The requirement: Find the folder which represents the current user's desktop.

You'd have thought this would have been easy, but no... Well, fairly easy. One possibility is to use the environment variable %USERPROFILE% and add "Desktop". Well, that'll work, until you're in a non-English locale, at which point Desktop becomes Escritorio or whatever. And then where are you?

So instead you delve into the Shell and use the entirely intuitive shell API. Note that, in place of CSIDL_DESKTOP in the code below, you can use any one of a large number of other CSIDL constants representing application data (CSIDL_APPDATA), the user's favourites folder (CSIDL_FAVORITES [sic]) and so on.

from win32com.shell import shell, shellcon

print shell.SHGetFolderPath (0, shellcon.CSIDL_DESKTOP, None, 0)