Results 1 to 10 of 10

Thread: Create Tree from list of files

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ilirska Bistrica, Slovenia
    Posts
    242

    Create Tree from list of files

    I have a list of files like that:
    Code:
    c:\folder1\file.txt
    c:\folder1\file2.txt
    c:\folder1\file3.txt
    c:\folder1\file4.txt
    c:\folder1\subfolder\file.txt
    c:\folder1\subfolder\file1.txt
    c:\folder1\subfolder\file2.txt
    c:\folder1\subfolder\file3.txt
    c:\folder1\subfolder\test\file.txt
    c:\folder1\subfolder\test\file1.txt
    c:\folder1\subfolder\test\file2.txt
    c:\folder2\file.txt
    c:\folder2\subfolder\file.txt
    
    AND SO ON
    Can someone tell me any possible way to make a tree out of that data?
    Zvonko Bostjancic
    Ilirska Bistrica, Slovenia
    [email protected]
    Using VS6 Professional with SP3
    Programming mostly in VB and I've started to learn VC++ & MFC

  2. #2
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    Now, how do you mean, make a tree? Do you want the info sent to a treeview, or do you want an ASCII file generated that does this:
    Code:
    c:\folder1\file.txt
               file2.txt
               file3.txt
               file4.txt
               subfolder\file.txt
                         file1.txt
                         file2.txt
                         file3.txt
                         test\file.txt
                              file1.txt
                              file2.txt
    c:\folder2\file.txt
               subfolder\file.txt
    -Excalibur

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ilirska Bistrica, Slovenia
    Posts
    242
    I'd like to send it to treeview:
    like this:
    Code:
    c:\
    |--folder
    |     \--subfolder
    |              \-test
    |                   |--file1.txt
    |                   \--file2.txt
    \--folder2
          \--file1.txt
    Zvonko Bostjancic
    Ilirska Bistrica, Slovenia
    [email protected]
    Using VS6 Professional with SP3
    Programming mostly in VB and I've started to learn VC++ & MFC

  4. #4
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Are you getting this as a string??? Or you want to actually go through the folders on your machine and populate the treeview?

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ilirska Bistrica, Slovenia
    Posts
    242
    Each line is a string, for example:
    Code:
    Dim tmpStr() As String, tmpS As String
    
    ReDim tmpStr(20) As String
    
    For I=1 To 4
       tmpS = "C:\Folder" & I
       For J = 1 to 5
           tmpStr((I - 1) * 4) + J) = tmpS & "\file" & J & ".txt"
       Next
    Next
    Here is an example of array with 20 items. From that data I need to populate treeview.
    Suggestions are very appreciated and welcome.

    P.S.: If code has errors, doesn't matter I wrote it in a minute just for example. The real code is much more complex.
    Zvonko Bostjancic
    Ilirska Bistrica, Slovenia
    [email protected]
    Using VS6 Professional with SP3
    Programming mostly in VB and I've started to learn VC++ & MFC

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ilirska Bistrica, Slovenia
    Posts
    242
    Mhm...

    Does noone have not even slightest idea what to do?
    Zvonko Bostjancic
    Ilirska Bistrica, Slovenia
    [email protected]
    Using VS6 Professional with SP3
    Programming mostly in VB and I've started to learn VC++ & MFC

  7. #7
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Sounds like a lot of work, what do you need it for?

  8. #8
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Not that much work Something like this:
    VB Code:
    1. Private Sub Form_Load()
    2.     Dim arrTemp(12) As String
    3.     Dim i As Integer
    4.     Dim j As Integer
    5.     Dim arrFolders() As String
    6.     Dim nod As Node
    7.     Dim strKey As String
    8.     Dim strPrevKey As String
    9.    
    10.     'assuming that the array holds these files/folders
    11.     arrTemp(0) = "c:\folder1\file.txt"
    12.     arrTemp(1) = "c:\folder1\file2.txt"
    13.     arrTemp(2) = "c:\folder1\file3.txt"
    14.     arrTemp(3) = "c:\folder1\file4.txt"
    15.     arrTemp(4) = "c:\folder1\subfolder\file.txt"
    16.     arrTemp(5) = "c:\folder1\subfolder\file1.txt"
    17.     arrTemp(6) = "c:\folder1\subfolder\file2.txt"
    18.     arrTemp(7) = "c:\folder1\subfolder\file3.txt"
    19.     arrTemp(8) = "c:\folder1\subfolder\test\file.txt"
    20.     arrTemp(9) = "c:\folder1\subfolder\test\file1.txt"
    21.     arrTemp(10) = "c:\folder1\subfolder\test\file2.txt"
    22.     arrTemp(11) = "c:\folder2\file.txt"
    23.     arrTemp(12) = "c:\folder2\subfolder\file.txt"
    24.    
    25.    
    26.     With TreeView1
    27.         .Sorted = True
    28.        
    29.         For i = 0 To UBound(arrTemp)
    30.             arrFolders = Split(arrTemp(i), "\")
    31.             strKey = ""
    32.            
    33.             For j = 0 To UBound(arrFolders)
    34.                        
    35.                 strKey = strKey & arrFolders(j) & "\"
    36.  
    37.                 On Error Resume Next
    38.                
    39.                 If j = 0 Then
    40.                     Set nod = .Nodes(strKey)
    41.                     If nod Is Nothing Then Set nod = .Nodes.Add(, , strKey, arrFolders(j))
    42.                    
    43.                 Else
    44.                     Set nod = .Nodes.Add(strPrevKey, tvwChild, strKey, arrFolders(j))
    45.                 End If
    46.                
    47.                 strPrevKey = strKey
    48.                 nod.Sorted = True
    49.                 nod.EnsureVisible
    50.             Next
    51.         Next
    52.     End With
    53. End Sub

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ilirska Bistrica, Slovenia
    Posts
    242
    I have a list of files (in text file) and from that I need to make a tree (in treeview).

    The program has it's own database (collection-driven) and it saves filenames (with paths and other data) in file and then it loads it to a treeview...
    Zvonko Bostjancic
    Ilirska Bistrica, Slovenia
    [email protected]
    Using VS6 Professional with SP3
    Programming mostly in VB and I've started to learn VC++ & MFC

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ilirska Bistrica, Slovenia
    Posts
    242
    Interesting code.....

    I'll check it out...
    Zvonko Bostjancic
    Ilirska Bistrica, Slovenia
    [email protected]
    Using VS6 Professional with SP3
    Programming mostly in VB and I've started to learn VC++ & MFC

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width