Saving Files Under Windows

achrist at easystreet.com achrist at easystreet.com
Mon Jun 16 12:25:55 EDT 2003


Tim Golden wrote:
> 
> In fact, there is a lot to be known about MS Windows in its various
>  incarnations that isn't known by the casual user, and not even by
>  the administrators in some cases. As a rule, direct access to the
>  registry is not the best way to read/write system info (unless of
>  course there is no other), not least because it changes so damned
>  often: what looked like a stable lookup in Win98 suddenly isn't >  there
>  when you get to Win2k.
> Functions like SHGetSpecialFolderPath, available via the shell module
>  in win32all will get pretty much anything you like of the [My > Documents]
>  variety, regardless of the environment, changes of location, use of
>  domain etc. At least, I've used them across a mixed Win2k / Win9x
>  setup with no problems at all.
> 
> Examples:
> 
> from win32com import storagecon
> from win32com.shell import shell, shellcon
> 
> def desktop (common=0):
>   return shell.SHGetSpecialFolderPath (0, (shellcon.CSIDL_DESKTOP,
> shellcon.CSIDL_COMMON_DESKTOPDIRECTORY)[common])
> 
> def application_data (common=0):
>   return shell.SHGetSpecialFolderPath (0, (shellcon.CSIDL_APPDATA,
> shellcon.CSIDL_COMMON_APPDATA)[common])
> 
> def personal_folder ():
>   return shell.SHGetSpecialFolderPath (0, shellcon.CSIDL_PERSONAL)
> my_documents = personal_folder
> 

This looks to be exactly what I need, if I can get it to work ...

Are these not portable to WinNT?  On NT 4.0 SP6,  I get:

>>> from win32com import storagecon
>>> from win32com.shell import shell, shellcon

>>> shell.SHGetSpecialFolderPath (0, (shellcon.CSIDL_DESKTOP,
... shellcon.CSIDL_COMMON_DESKTOPDIRECTORY)[0])
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
pywintypes.com_error: (-2147467263, 'Not implemented', None, None)

>>> shell.SHGetSpecialFolderPath (0, (shellcon.CSIDL_APPDATA,
... shellcon.CSIDL_COMMON_APPDATA)[0])
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
pywintypes.com_error: (-2147467263, 'Not implemented', None, None)


Al




More information about the Python-list mailing list