Open Folder in Desktop

Jimmy Retzlaff jimmy at retzlaff.com
Tue Jan 25 09:32:16 CET 2005


Kamilche wrote:
> Is there a command you can execute in Python that will open a window
on
> the desktop, such as 'My Documents'? Kind of like 'system', but for
> folder names, not just programs. I'm running on Windows 2000.

There are two issues here. The first is how to open a folder and the
second is how to resolve "special" folders. Folders are "documents"
typically associated with the explorer.exe application. To open a
document with its default app (e.g., a folder), use os.startfile which
is included in Python. For example:

import os
os.startfile(r'c:\windows')

Folders like My Documents, My Pictures, etc. are special and you need to
determine their actual path before you can open them. The pywin32
extensions
(https://sourceforge.net/project/showfiles.php?group_id=78018) include a
way to get at this:

from win32com.shell import shellcon, shell
path = shell.SHGetFolderPath(0, shellcon.CSIDL_MYPICTURES, 0, 0)
os.startfile(path)

Google for CSIDL to find the constants to use for other special folders.

Jimmy



More information about the Python-list mailing list