Python win32com.shell.shell.SHGetSpecialFolderPath() Examples
The following are 12
code examples of win32com.shell.shell.SHGetSpecialFolderPath().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
win32com.shell.shell
, or try the search function
.
Example #1
Source File: testShell.py From ironpython2 with Apache License 2.0 | 6 votes |
def testShellLink(self): desktop = str(shell.SHGetSpecialFolderPath(0, CSIDL_DESKTOP)) num = 0 shellLink = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink) persistFile = shellLink.QueryInterface(pythoncom.IID_IPersistFile) names = [os.path.join(desktop, n) for n in os.listdir(desktop)] programs = str(shell.SHGetSpecialFolderPath(0, CSIDL_PROGRAMS)) names.extend([os.path.join(programs, n) for n in os.listdir(programs)]) for name in names: try: persistFile.Load(name,STGM_READ) except pythoncom.com_error: continue # Resolve is slow - avoid it for our tests. #shellLink.Resolve(0, shell.SLR_ANY_MATCH | shell.SLR_NO_UI) fname, findData = shellLink.GetPath(0) unc = shellLink.GetPath(shell.SLGP_UNCPRIORITY)[0] num += 1 if num == 0: # This isn't a fatal error, but is unlikely. print "Could not find any links on your desktop or programs dir, which is unusual"
Example #2
Source File: windows.py From marsnake with GNU General Public License v3.0 | 6 votes |
def setup_environment(): """Define any extra environment variables for use in CleanerML and Winapp2.ini""" csidl_to_environ('commonappdata', shellcon.CSIDL_COMMON_APPDATA) csidl_to_environ('documents', shellcon.CSIDL_PERSONAL) # Windows XP does not define localappdata, but Windows Vista and 7 do csidl_to_environ('localappdata', shellcon.CSIDL_LOCAL_APPDATA) csidl_to_environ('music', shellcon.CSIDL_MYMUSIC) csidl_to_environ('pictures', shellcon.CSIDL_MYPICTURES) csidl_to_environ('video', shellcon.CSIDL_MYVIDEO) # LocalLowAppData does not have a CSIDL for use with # SHGetSpecialFolderPath. Instead, it is identified using # SHGetKnownFolderPath in Windows Vista and later try: path = get_known_folder_path('LocalAppDataLow') except: logger().error('exception identifying LocalAppDataLow') else: set_environ('LocalAppDataLow', path)
Example #3
Source File: utils.py From winpython with MIT License | 6 votes |
def get_special_folder_path(path_name): """Return special folder path""" from win32com.shell import shell, shellcon for maybe in """ CSIDL_COMMON_STARTMENU CSIDL_STARTMENU CSIDL_COMMON_APPDATA CSIDL_LOCAL_APPDATA CSIDL_APPDATA CSIDL_COMMON_DESKTOPDIRECTORY CSIDL_DESKTOPDIRECTORY CSIDL_COMMON_STARTUP CSIDL_STARTUP CSIDL_COMMON_PROGRAMS CSIDL_PROGRAMS CSIDL_PROGRAM_FILES_COMMON CSIDL_PROGRAM_FILES CSIDL_FONTS""".split(): if maybe == path_name: csidl = getattr(shellcon, maybe) return shell.SHGetSpecialFolderPath( 0, csidl, False ) raise ValueError( "%s is an unknown path ID" % (path_name,) )
Example #4
Source File: windows_post_install.py From GridCal with GNU General Public License v3.0 | 6 votes |
def get_special_folder_path(path_name): try: import pythoncom except ImportError: print("pywin32 is required to run this script manually", file=sys.stderr) sys.exit(1) from win32com.shell import shell, shellcon path_names = ['CSIDL_COMMON_STARTMENU', 'CSIDL_STARTMENU', 'CSIDL_COMMON_APPDATA', 'CSIDL_LOCAL_APPDATA', 'CSIDL_APPDATA', 'CSIDL_COMMON_DESKTOPDIRECTORY', 'CSIDL_DESKTOPDIRECTORY', 'CSIDL_COMMON_STARTUP', 'CSIDL_STARTUP', 'CSIDL_COMMON_PROGRAMS', 'CSIDL_PROGRAMS', 'CSIDL_PROGRAM_FILES_COMMON', 'CSIDL_PROGRAM_FILES', 'CSIDL_FONTS'] for maybe in path_names: if maybe == path_name: csidl = getattr(shellcon, maybe) return shell.SHGetSpecialFolderPath(0, csidl, False) raise ValueError("%s is an unknown path ID" % (path_name,))
Example #5
Source File: dump_link.py From ironpython2 with Apache License 2.0 | 5 votes |
def DumpFavorites(): favfold = str(shell.SHGetSpecialFolderPath(0, shellcon.CSIDL_FAVORITES)) print "Your favourites are at", favfold os.path.walk(favfold, FavDumper, None)
Example #6
Source File: windows.py From marsnake with GNU General Public License v3.0 | 5 votes |
def csidl_to_environ(varname, csidl): """Define an environment variable from a CSIDL for use in CleanerML and Winapp2.ini""" try: sppath = shell.SHGetSpecialFolderPath(None, csidl) except: logger().error('exception when getting special folder path for %s', varname) return # there is exception handling in set_environ() set_environ(varname, sppath)
Example #7
Source File: osutils.py From p2ptv-pi with MIT License | 5 votes |
def get_home_dir(): return shell.SHGetSpecialFolderPath(0, 40)
Example #8
Source File: osutils.py From p2ptv-pi with MIT License | 5 votes |
def get_appstate_dir(): return shell.SHGetSpecialFolderPath(0, 26)
Example #9
Source File: osutils.py From p2ptv-pi with MIT License | 5 votes |
def get_picture_dir(): return shell.SHGetSpecialFolderPath(0, 39)
Example #10
Source File: osutils.py From p2ptv-pi with MIT License | 5 votes |
def get_desktop_dir(): return shell.SHGetSpecialFolderPath(0, 16)
Example #11
Source File: __init__.py From pyrexecd with MIT License | 5 votes |
def getpath(csidl): return shell.SHGetSpecialFolderPath(None, csidl, 0)
Example #12
Source File: dump_link.py From Email_My_PC with MIT License | 5 votes |
def DumpFavorites(): favfold = str(shell.SHGetSpecialFolderPath(0, shellcon.CSIDL_FAVORITES)) print "Your favourites are at", favfold os.path.walk(favfold, FavDumper, None)