Announcement

Collapse
No announcement yet.

Treeview Directory Structure

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Treeview Directory Structure

    I'm working on a project that requires me to parse out directory
    paths from an array (Each element contains one full path) into a treeview
    (kinda like BFF).

    I'm working on the fill code now but before I re-invent the wheel
    does anyone have any working code to do this?

    I haven't seen anything in the forums yet. My LDAP example
    does something similar but it's not quite usable for what I need.

    ------------------
    Every day I try to learn one thing new,
    but new things to learn are increasing exponentially.
    At this rate I’m becoming an idiot faster and faster !!!
    ------------------
    George W. Bleck
    Lead Computer Systems Engineer
    KeySpan Corporation



    [This message has been edited by George Bleck (edited March 12, 2003).]
    <b>George W. Bleck</b>
    <img src='http://www.blecktech.com/myemail.gif'>

    #2
    some ideas if you can't find 'canned' code...

    putting a 'folder list' into a hierarchical structure (e.g, a treeview control) might be a lot easier if you add the nodes 'on the fly' whilst recursing the directory tree. that way you always have the "parent" handy and can avoid all that string parsing.

    but if you are getting a list of paths as an array (i.e., you are not generating the list of folders), first step is to sort the list.

    in fact...you might take a look at my files comparison code at <a href="http://.]
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


      #3
      mike,

      thanks for the response, i went the "new wheel" route for the experience.
      i then started playing around with and came up with the below code snippet.
      it doesn't return anything as i'm playing with if i want to use a global string
      for the return or not but it does make a good template for someone to work from.
      it uses "on demand" filling of nodes and kills collapsed nodes to save memory.
      if people are interested i'll flesh it in more and post in source code.

      beta code deleted...

      see http://www.powerbasic.com/support/pb...ad.php?t=23778

      ------------------
      every day i try to learn one thing new,
      but new things to learn are increasing exponentially.
      at this rate i’m becoming an idiot faster and faster !!!
      ------------------
      george w. bleck
      lead computer systems engineer
      keyspan corporation



      [this message has been edited by george bleck (edited march 15, 2003).]
      <b>George W. Bleck</b>
      <img src='http://www.blecktech.com/myemail.gif'>

      Comment


        #4
        That's Real Pretty!! George

        Thanks!!!
        Brad

        ------------------
        Wash DC Area
        mailto:[email protected][email protected]</A>
        mailto:[email protected][email protected]</A>

        Comment


          #5
          Which compiler version? Dates of Win32API and COMMCTRL.INC?

          On my system using PB/Win 7.0 the dialog comes up, shows drives "S" and "C" (correct), arrow keys move between S and C, but the tree nodes will not expand in response to either arrow keys (left and right arrow should expand/contract) or mouse clicks on the little "plus-sign" boxes.

          Betcha we have some differences in the casting of LONG/DWORDS somewhere in the TVN_xxxx messages.

          MCM

          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


            #6
            Compiler: PB v7.0
            Includes: Latest versions of Win32api.inc and commctrl.inc from the website.

            ------------------
            Every day I try to learn one thing new,
            but new things to learn are increasing exponentially.
            At this rate I’m becoming an idiot faster and faster !!!
            ------------------
            George W. Bleck
            Lead Computer Systems Engineer
            KeySpan Corporation
            <b>George W. Bleck</b>
            <img src='http://www.blecktech.com/myemail.gif'>

            Comment


              #7
              Got it to work by using some SELECT CASE AS LONG and testing BITS???(value) in IF statements.

              Once I got there, it's really nice.

              (The change in integer comparison behavior v6=>v7 is a real PITA).

              FWIW, you can get BFF to do this by using the %BIF_BROWSEINCLUDEFILES flag. BFF will also go hunting for computers and printers:

              From Win32API.INC:
              Code:
              %BIF_BROWSEINCLUDEURLS  = &H0080   ' Allow URLs to be displayed or entered. (Requires BIF_USENEWUI)
              %BIF_BROWSEFORCOMPUTER  = &H00001000  ' Browsing for Computers.
              %BIF_BROWSEFORPRINTER   = &H00002000  ' Browsing for Printers
              %BIF_BROWSEINCLUDEFILES = &H00004000  ' Browsing for Everything
              MCM




              [This message has been edited by Michael Mattias (edited March 15, 2003).]
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


                #8
                I've used BFF quite often for these things..it's just that I wanted
                something I could customize a little more then Billy allows me to.

                ------------------
                Every day I try to learn one thing new,
                but new things to learn are increasing exponentially.
                At this rate I’m becoming an idiot faster and faster !!!
                ------------------
                George W. Bleck
                Lead Computer Systems Engineer
                KeySpan Corporation
                <b>George W. Bleck</b>
                <img src='http://www.blecktech.com/myemail.gif'>

                Comment


                  #9
                  If anyone had downloaded the previous version and wish to continue playing with
                  it I replaced the original and added the following:

                  Added System Image List support so it shows the correct icons in the list.
                  Added view hidden and system files
                  Added show dirs first

                  It works on WinXP, not sure of the other platforms though.
                  If anyone wants to give feedback it would be appreciated.

                  ------------------
                  Every day I try to learn one thing new,
                  but new things to learn are increasing exponentially.
                  At this rate I’m becoming an idiot faster and faster !!!
                  ------------------
                  George W. Bleck
                  Lead Computer Systems Engineer
                  KeySpan Corporation



                  [This message has been edited by George Bleck (edited March 15, 2003).]
                  <b>George W. Bleck</b>
                  <img src='http://www.blecktech.com/myemail.gif'>

                  Comment


                    #10
                    George,

                    Loaded the code in Win98SE in PB Win 7.01, Glad to report it ran "out of the box", no problems.

                    Nice work!

                    ------------------
                    Rick Angell

                    [This message has been edited by Richard Angell (edited March 15, 2003).]
                    Rick Angell

                    Comment


                      #11
                      see final version here

                      http://www.powerbasic.com/support/pb...ad.php?t=23778

                      ------------------
                      every day i try to learn one thing new,
                      but new things to learn are increasing exponentially.
                      at this rate i’m becoming an idiot faster and faster !!!
                      ------------------
                      george w. bleck
                      lead computer systems engineer
                      keyspan corporation
                      <b>George W. Bleck</b>
                      <img src='http://www.blecktech.com/myemail.gif'>

                      Comment


                        #12
                        There was a minor glitch in the Source Code posting that
                        prevented the Icons from showing on Win9x systems

                        Code:
                        The line:
                        TreeView_SetImageList hTreeview, SHGETFILEINFO( "\\", 0, structSHFileInfo, SIZEOF(structSHFileInfo), %SHGFI_USEFILEATTRIBUTES OR %SHGFI_SmallICON OR %SHGFI_SYSICONINDEX), %TVSIL_NORMAL

                        Code:
                        Has been corrected to...
                        TreeView_SetImageList hTreeview, SHGETFILEINFO( "C:\", 0, structSHFileInfo, SIZEOF(structSHFileInfo), %SHGFI_USEFILEATTRIBUTES OR %SHGFI_SmallICON OR %SHGFI_SYSICONINDEX), %TVSIL_NORMAL

                        ------------------
                        Every day I try to learn one thing new,
                        but new things to learn are increasing exponentially.
                        At this rate I’m becoming an idiot faster and faster !!!
                        ------------------
                        George W. Bleck
                        Lead Computer Systems Engineer
                        KeySpan Corporation

                        [This message has been edited by George Bleck (edited March 17, 2003).]
                        <b>George W. Bleck</b>
                        <img src='http://www.blecktech.com/myemail.gif'>

                        Comment


                          #13
                          It's probably better to use "*" as path in this case, I think. Some
                          people have their systems installed on other drives than C, so..

                          Did a quick test, "*" works fine in Win98.

                          ------------------
                          http://www.tolkenxp.com/pb
                          Download: incLean, PBcodec, custom controls and code, etc.
                          Borje Hagsten - [email protected]

                          Comment


                            #14
                            Thanks for the feedback Borje.

                            I'm gonna run it through my test environment at work when I get
                            the chance. I've got one of every OS for compatability testing
                            so I'll try it with your modification.



                            ------------------
                            Every day I try to learn one thing new,
                            but new things to learn are increasing exponentially.
                            At this rate I’m becoming an idiot faster and faster !!!
                            ------------------
                            George W. Bleck
                            Lead Computer Systems Engineer
                            KeySpan Corporation
                            <b>George W. Bleck</b>
                            <img src='http://www.blecktech.com/myemail.gif'>

                            Comment


                              #15
                              Nice work George! When I encountered an empty directory though, I wanted to keep trying to open it because nothing seems to happen.
                              The following code (replaces your libBFF_TVAddSubfilesToNode sub) removes the "+" on that node if it has no children. This gives
                              you visual confirmation that you did indeed click on the "+" or double-click on the folder.
                              It now behaves more like windows explorer. (never thought I would think that was a good thing)

                              Code:
                              Sub libBFF_TVAddSubfilesToNode(ByVal hTreeview As Dword, ByVal hITem As Dword)
                              	Local lngIndex As Long
                              	Local strArray() As String
                              	Local strDirFind As String
                              	Local strPath As String 
                              	Local DirCount As Long 
                              	Local structTV_Item As TV_ITEM
                              	strPath = libBFF_TVGetFullPath(hTreeview, hItem)
                              	'Get the dirs
                              	strDirFind = Dir$(strPath & "\*.*", gstruct_libBFF_Settings.dwdDirAttributeMask)
                              	Do Until strDirFind = ""
                              		If (GetAttr(strPath & "\" & strDirFind) And 16) = 16 And Err = 0 Then
                              			ReDim Preserve strArray(UBound(strArray) + 1)
                              			strArray(UBound(strArray) ) = strDirFind
                              		End If
                              		strDirFind = Dir$
                              	Loop
                              	Array Sort strArray(), Collate UCase
                              	For lngIndex = 0 To UBound(strArray)
                              		libBFF_TVInsertItem hTreeview, hItem, strArray(lngIndex), 1, libBFF_GetIconIndex(strPath & "\" & strArray(lngIndex) )
                              	Next lngIndex
                              	DirCount=lngIndex
                              	If gstruct_libBFF_Settings.dwdShowType > 0 Then
                              		Erase strArray()
                              		'get the files
                              		strDirFind = Dir$(strPath & "\" & Trim$(gstruct_libBFF_Settings.strFileMatchMask), gstruct_libBFF_Settings.dwdFileAttributeMask)
                              		Do Until strDirFind = ""
                              			ReDim Preserve strArray(UBound(strArray) + 1)
                              			strArray(UBound(strArray) ) = strDirFind
                              			strDirFind = Dir$
                              		Loop
                              		Array Sort strArray(), Collate UCase
                              		For lngIndex = 0 To UBound(strArray)
                              			libBFF_TVInsertItem hTreeview, hItem, strArray(lngIndex), 0, libBFF_GetIconIndex(strPath & "\" & strArray(lngIndex) )
                              		Next lngIndex
                              	End If
                              	If DirCount+lngIndex=0 Then  'Directory count and file count=0? 
                              	    structTV_Item.mask=%TVIF_CHILDREN
                              	    structTV_Item.hItem=hItem        
                              	    structTV_Item.cChildren=0
                              	    Call SendMessage( hTreeview, %TVM_SETITEM, 0, ByVal VarPtr( structTV_ITEM ) )
                              	End If 
                              End Sub
                              Thanks for the nice routine,

                              David Kenny

                              ------------------


                              [This message has been edited by David Kenny (edited March 19, 2003).]

                              Comment


                                #16
                                David,

                                Thanks for the addition, I was going to put that feature in and completely forgot!

                                I've updated it in the source code forum as well. I made some modifications
                                to the variable names to fit my name convention hope you don't mind

                                The next couple of features I'd like to add when I have time are:

                                (1) The ability to THREAD fill large directories
                                (2) Allow system folder's on the root (like Desktop, My Docs, etc.)

                                Anyone wishing to help please feel free!

                                ------------------
                                Every day I try to learn one thing new,
                                but new things to learn are increasing exponentially.
                                At this rate I’m becoming an idiot faster and faster !!!
                                ------------------
                                George W. Bleck
                                Lead Computer Systems Engineer
                                KeySpan Corporation
                                <b>George W. Bleck</b>
                                <img src='http://www.blecktech.com/myemail.gif'>

                                Comment


                                  #17
                                  No problem George, I saw that after I posted and didn't take the time to fix it. Must be lazy.

                                  David

                                  ------------------

                                  Comment


                                    #18
                                    Added background fill of nodes now...plus a "loading" indicator.

                                    ------------------
                                    Every day I try to learn one thing new,
                                    but new things to learn are increasing exponentially.
                                    At this rate I’m becoming an idiot faster and faster !!!
                                    ------------------
                                    George W. Bleck
                                    Lead Computer Systems Engineer
                                    KeySpan Corporation

                                    [This message has been edited by George Bleck (edited March 28, 2003).]
                                    <b>George W. Bleck</b>
                                    <img src='http://www.blecktech.com/myemail.gif'>

                                    Comment


                                      #19
                                      Fred,

                                      That WIN32API.INC in the libBFF.INC file has me puzzled...

                                      It is called before the libBFF.INC in the main program so
                                      there is no problem with forward referenced function/subs.

                                      ------------------
                                      Every day I try to learn one thing new,
                                      but new things to learn are increasing exponentially.
                                      At this rate I’m becoming an idiot faster and faster !!!
                                      ------------------
                                      George W. Bleck
                                      Lead Computer Systems Engineer
                                      KeySpan Corporation
                                      <b>George W. Bleck</b>
                                      <img src='http://www.blecktech.com/myemail.gif'>

                                      Comment


                                        #20
                                        Anyone that had use the previous BFF code should download the latest
                                        version as it fixes a handle leak plus some other fixes and tweaks as well.


                                        Note: The global array name has changed to fit the naming convention better.
                                        You may need to change your code slightly to accomodate the new version


                                        ------------------
                                        Every day I try to learn one thing new,
                                        but new things to learn are increasing exponentially.
                                        At this rate I’m becoming an idiot faster and faster !!!
                                        ------------------
                                        George W. Bleck
                                        Lead Computer Systems Engineer
                                        KeySpan Corporation

                                        [This message has been edited by George Bleck (edited March 29, 2003).]
                                        <b>George W. Bleck</b>
                                        <img src='http://www.blecktech.com/myemail.gif'>

                                        Comment

                                        Working...
                                        X
                                        😀
                                        🥰
                                        🤢
                                        😎
                                        😡
                                        👍
                                        👎