Hi,

In vb.net, how would you search a folder and get it to make a list of the files in the directory and what sub-folders the files are in are in? Then, put the results in a multiline textbox.

The list would look something like if we were searching in C:\foo:

C:\foo\bar.txt
C:\foo\carrots\potatoes.exe
...

Thanks,

James

Recommended Answers

All 3 Replies

basically you want to print the directory structure. I dont know the vb.net syntax much but u can try this:

search for all files inside a folder (using recursion) and then try to get the parent path of the file. Then you can save that path in a multiline textbox

basically you want to print the directory structure. I dont know the vb.net syntax much but u can try this:

search for all files inside a folder (using recursion) and then try to get the parent path of the file. Then you can save that path in a multiline textbox

Can anybody tell me how to do this is vb?

Member Avatar for Unhnd_Exception
Private Sub btnGetFiles_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnGetFiles.Click  

    PrintDirectory("C:\TestD")

End Sub

Private Sub PrintDirectory(ByVal DirectoryPath As String)

    For Each FileName As String In System.IO.Directory.GetFiles(DirectoryPath)
        txtDirectoryInfo.Text &= FileName & vbCrLf
    Next

    For Each Directory As String In System.IO.Directory.GetDirectories(DirectoryPath)
        PrintDirectory(Directory)
    Next

End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.