[PythonCE] How to determine special folder location

rodi c22rs at web.de
Tue Mar 30 00:02:43 CEST 2010


Hello PytonCE users,

have solved the question. The appropriate function 
is 'SHGetSpecialFolderPath': see
http://msdn.microsoft.com/en-us/library/aa931257.aspx

May be this info and the follwing code snippet is helpfull to others :)

import ctypes
from time import sleep

HANDLE = ctypes.c_ulong
HWND = HANDLE
INT = ctypes.c_int
BOOL = ctypes.c_int

SHGetSpecialFolderPath = ctypes.windll.coredll.SHGetSpecialFolderPath
# BOOL SHGetSpecialFolderPath( HWND hwndOwner, LPTSTR lpszPath, int nFolder, 
BOOL fCreate );
SHGetSpecialFolderPath.argtypes = [HWND, ctypes.c_wchar_p, INT, BOOL]
MAX_PATH = 260
path = ctypes.create_unicode_buffer(MAX_PATH)
for i in range(0, 60): #[CSIDL_STARTMENU, CSIDL_PROGRAMS]:
    try:
        SHGetSpecialFolderPath( 0,  path, i, 0)
        if len(path.value)>0:
            print i, path.value
        else:
            print i, 'not supported'
    except Exception, e:
        print i, 'exception', e
sleep(5)


Cheers rodi.


More information about the PythonCE mailing list