Get Special Folders (ie Desktop location)
Tim Golden
tim.golden at viacom-outdoor.co.uk
Tue Nov 30 03:59:21 EST 2004
[colin.steadman at gmail.com]
| I'm just starting out writing Python scripts (in PSP), and need to
| find the location of Windows special folders such as 'My Documents'
| and 'Desktop' so that I can save files in the right place. Is there
| any method I can use in Python to get these?
|
| If I were doing this in VBScript it'd be:
|
| Dim WSHShell
| Set WSHShell = WScript.CreateObject("WScript.Shell")
| msgbox WSHShell.SpecialFolders("Desktop")
|
You can do that in Python using the pywin32 extensions
either by using the Wshell objects as you have done:
<code>
import win32com.client
WShell = win32com.client.Dispatch ("WScript.Shell")
WShell.SpecialFolders ("Desktop")
</code>
or by using the shell module from the same package.
I've got a module which wraps the common ones for
convenience:
http://tgolden.sc.sabren.com/python/winshell.html
but essentially what you're doing is this:
<code>
from win32com.shell import shell, shellcon
shell.SHGetPathFromIDList (
shell.SHGetSpecialFolderLocation (
0, shellcon.CSIDL_DESKTOP
)
)
</code>
TJG
________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________
More information about the Python-list
mailing list