How to list directory hierarchy in PyGTK treeview widget?

Posted by lyrae on Stack Overflow See other posts from Stack Overflow or by lyrae
Published on 2010-03-31T07:30:36Z Indexed on 2010/03/31 7:33 UTC
Read the original article Hit count: 374

Filed under:
|
|

I am trying to generate a hierarchical directory listing in pyGTK.

Currently, I have this following directory tree:

/root
    folderA
        - subdirA
            - subA.py
        - a.py

    folderB
        - b.py 

I have written a function that -almost- seem to work:

def go(root, piter = None):

    for filename in os.listdir(root):

        isdir = os.path.isdir(os.path.join(root, filename))

        piter = self.treestore.append(piter, [filename])    

        if isdir == True:
            go(os.path.join(root, filename), piter)

This is what i get when i run the app:
alt text

I also think my function is inefficient and that i should be using os.walk(), since it already exists for such purpose.

How can I, and what is the proper/most efficient way of generating a directory tree with pyGTK?

© Stack Overflow or respective owner

Related posts about python

Related posts about pygtk