System Folders in python

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:

AllUsersDesktop
AllUsersStartMenu
AllUsersPrograms
AllUsersStartup
Desktop
Favorites
Fonts
MyDocuments
NetHood
PrintHood
Recent
SendTo
StartMenu
Startup
Templates

With thanks to Peter Jessop

Advertisements

About Mr Chimp

I make music, draw pictures, browse the internet, programme, and make sweet, sweet cups of tea until the early hours.
This entry was posted in Uncategorized. Bookmark the permalink.

3 Responses to System Folders in python

  1. Danimal says:

    I like the sound of progress with this one.

  2. Mr Chimp says:

    Yeah, this is about as far as I’ve got really… There’s a way to go yet…

    Plus I’m not sure what happens on windows 7 when you’ve got “Program Files” and “Program Files (x32)”…

  3. Mr Chimp says:

    Anyway, aren’t you supposed to be getting away from it all? :p

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s