Well, it’s a Thursday morning. I know what you’re looking forward to: a post about finding the location of system folders in Python. Oh, you we’re going to say “the weekend”? You’re looking in the wrong place for that…
The “My Documents” folder on Windows isn’t always in the same place. In fact it’s almost always in a different place. So if you want to refer to it in your code you’re going to need some way of working out where it is.
First off, if you don’t have it already you’ll need pywin32. Download and install that.
Next, the code:
import win32com.client objShell = win32com.client.Dispatch("WScript.Shell") allUserDocs = objShell.SpecialFolders("AllUsersDesktop") print(allUserDocs)
This code will find you the path to the shared desktop folder (AKA “AllUsersDesktop”).
You can replace “AllUsersDesktop” with any of the following:
With thanks to Peter Jessop