Can I use library abstractions in python?

I use:

for root, dirs, files in os.walk(rootDir):

to navigate directories. Everything is awesome. However, I am running Windows 7, which of course has an abstraction of the library. So, for example, an image library can map to c:\users\meand is c:\users\share there a way to use this library abstraction using python?

+5
source share
2 answers

If I’m not mistaken about how this function works (I actually don’t have a Win7 window in front of me), you will have to turn to the Windows APIs to access the libraries.

MSDN Magazine, , , , , , . fancy file-chooser ( , , ), API- .

, Windows dev IShellLibrary .

, , COM-API, , , win32com Python. ( ctypes C- COM-, .) , - COM- Python - PyPI ActiveState, .

, , IronPython .NET API .

+3

Pywin32 (218) :

import pythoncom
from win32com.shell import shell, shellcon
from win32com import storagecon
import os

kfm = pythoncom.CoCreateInstance(shell.CLSID_KnownFolderManager, None,
        pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IKnownFolderManager)
libs_folder = kfm.GetFolder(shell.FOLDERID_Libraries)
libs_path = libs_folder.GetPath()

for lib_file in os.listdir(libs_path):
    if os.path.splitext(lib_file)[1] == '.library-ms':
        print lib_file
        i = shell.SHCreateItemFromParsingName(os.path.join(libs_path, lib_file),
                                              None, shell.IID_IShellItem)
        lib = pythoncom.CoCreateInstance(shell.CLSID_ShellLibrary, None,
                                         pythoncom.CLSCTX_INPROC, shell.IID_IShellLibrary)
        lib.LoadLibraryFromItem(i, storagecon.STGM_READ)
        for folder in lib.GetFolders():
            print '\t' + folder.GetDisplayName(shellcon.SHGDN_FORPARSING)
0

All Articles