[python-win32] explorer clone

Mark Hammond mhammond at skippinet.com.au
Tue Sep 27 03:57:00 CEST 2005


> I'm trying to make an explorer clone using python-win32.(not the tree.
> just the folderview on the right side.)
> I know that I have to use the IShellFolder&IShellView, but don't know
> how to.

If you are writing a clone and are only interested in the file system, there
would be no need to use the shell interfaces at all - you could similate
most of it in pure-python.

If you wanted to use the shell interfaces so that you see everything
explorer does, you would only need to use IShellFolder.  IShellView is only
used if you want to provide your own view *inside* explorer.

If you were hoping to reuse the Explorer IShellView implementations inside
your own application, I think you would have a battle on your hands.

Here is some code that vaguely demonstrates how to use IShellFolder (which I
also just checked into the win32comext\shell\demos directory)

# A little sample that walks from the desktop into child
# items.
from win32com.shell import shell, shellcon

def walk(folder, depth=2, indent=""):
    try:
        pidls = folder.EnumObjects(0, shellcon.SHCONTF_FOLDERS)
    except shell.error:
        # no items
        return
    for pidl in pidls:
        dn = folder.GetDisplayNameOf(pidl,
                                     shellcon.SHGDN_NORMAL)
        print indent, dn
        if depth:
            try:
                child = folder.BindToObject(pidl, None,
                                      shell.IID_IShellFolder)
            except shell.error:
                pass
            else:
                walk(child, depth-1, indent+" ")

walk(shell.SHGetDesktopFolder())


Mark



More information about the Python-win32 mailing list