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

Edited 5 Years Ago by jamesl22: n/a

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?

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
This question has already been answered. Start a new discussion instead.