Display the local files in tree view list

How can i list the local system files in a treeview list pls give some idea's thank you
anp_mcaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bsharathCommented:
Try this...

tree /a > c:\tree.txt
0
anp_mcaAuthor Commented:
The above single line code  is  enough or not  
0
bsharathCommented:
have you tried it.Is this not what you want
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

GrahamSkanRetiredCommented:
This uses VB6 code to fill the tree
Option Explicit
 
Private Sub Command1_Click()
    Dim strTopFolder As String
    Dim Nd As Node
 
    strTopFolder = "C:\Winnt"
    TreeView1.Nodes.Add , , strTopFolder, strTopFolder
    AppendChildFolders strTopFolder, TreeView1
    TreeView1.Nodes(1).Expanded = True
End Sub
 
Private Sub AppendChildFolders(strPath As String, TreeView1 As TreeView)
    Dim strFolder As String
    Dim strFolders() As String
    Dim iFolderCount As Integer
    Dim i As Integer
    
    strFolder = Dir$(strPath & "\*", vbDirectory)
    Do Until strFolder = ""
        If (GetAttr(strPath & "\" & strFolder) And vbDirectory) = vbDirectory Then
            If Left$(strFolder, 1) <> "." Then
                ReDim Preserve strFolders(iFolderCount)
                strFolders(iFolderCount) = strFolder
                iFolderCount = iFolderCount + 1
            End If
        End If
        strFolder = Dir$()
    Loop
    For i = 0 To iFolderCount - 1
        TreeView1.Nodes.Add strPath, tvwChild, strPath & "\" & strFolders(i), strFolders(i)
        AppendChildFolders strPath & "\" & strFolders(i), TreeView1
    Next
    DoEvents
End Sub

Open in new window

0
Éric MoreauSenior .Net ConsultantCommented:
0
anp_mcaAuthor Commented:
GrahamSkan: I am used ur code but the strFolder value is null so it could not be active the for loop now wt can i do
0
GrahamSkanRetiredCommented:
It works in my tests.
I cannot see how strFolder can be Null. It can be a zero length string, but if it is, it does not get included in the sub-folder search.
Which line gives the error?
0
anp_mcaAuthor Commented:
strFolder = Dir$(strPath & "\*", vbDirectory)

In runtime when the code reach this line i got a error message.
0
GrahamSkanRetiredCommented:
Does the folder in line 7 exist?

If you don't have C:\WinNT on your system, have you changed it to the one that you want loaded into the TreeView?

If it does exist, what is the error message number, please? And the message text, if it is in English?
0
anp_mcaAuthor Commented:
I would try to change the directory name but it seems the error.If the code need to set the properties, pls tell me .Then the error message is "Runtime error 35602". When i click the command button the tree view show the given dir name ex: c:\ .
0
anp_mcaAuthor Commented:
More than one time i clicked the button that time i got the error message " the key is not a unique collecction."
0
anp_mcaAuthor Commented:
I got one error imagelist must be initialized before it is used. tell me the solution for remove the error . already i set the properties in listview control.
0
GrahamSkanRetiredCommented:
The original code will not work if it is run twice. This new version clears the list before running so that it can be run as many times as you wish.

I have also added some logging. The log file will  be saved in the root of your C: drive, called something like "tvw08042.log". Please attach the file here if the code still does not run properly for you.
Option Explicit
 
Private Sub Command1_Click()
    Dim strTopFolder As String
    Dim Nd As Node
    TreeView1.Nodes.Clear
    strTopFolder = "C:\Winnt"
    WriteLog "*********************************"
    WriteLog "Adding: " & strTopFolder & "  Key: " & strTopFolder
    TreeView1.Nodes.Add , , strTopFolder, strTopFolder
    AppendChildFolders strTopFolder, TreeView1
    TreeView1.Nodes(1).Expanded = True
End Sub
 
Private Sub AppendChildFolders(strPath As String, TreeView1 As TreeView)
    Dim strFolder As String
    Dim strFolders() As String
    Dim iFolderCount As Integer
    Dim i As Integer
    
    strFolder = Dir$(strPath & "\*", vbDirectory)
    Do Until strFolder = ""
        If (GetAttr(strPath & "\" & strFolder) And vbDirectory) = vbDirectory Then
            If Left$(strFolder, 1) <> "." Then
                ReDim Preserve strFolders(iFolderCount)
                strFolders(iFolderCount) = strFolder
                iFolderCount = iFolderCount + 1
            End If
        End If
        strFolder = Dir$()
    Loop
    For i = 0 To iFolderCount - 1
        WriteLog "Adding: " & strFolders(i) & vbTab & "  Key: " & strPath & "\" & strFolders(i)
        TreeView1.Nodes.Add strPath, tvwChild, strPath & "\" & strFolders(i), strFolders(i)
        AppendChildFolders strPath & "\" & strFolders(i), TreeView1
    Next
    DoEvents
End Sub
Sub WriteLog(strText As String)
    Dim f As Integer
    f = FreeFile
    Open "C:\tvw" & Format(Now, "yy") & Format(Format(Now, "y"), "000") & ".log" For Append As #f
        Print #f, Format(Now, "hh:nn ss ") & strText
    Close #f
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
anp_mcaAuthor Commented:
Ok
0
Computer101Commented:
Forced accept.

Computer101
EE Admin
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.