All files in a folder to ListView?

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
3 posts Page 1 of 1
Contributors
User avatar
CodenBoy
Top Poster
Top Poster
Posts: 103
Joined: Sun Jul 15, 2012 4:06 pm

All files in a folder to ListView?
CodenBoy
Hello guys,

I just need little help, i just want a code that can make this:

If i have a listview, and it has 2 columns, first is called "File Name" and second called "path" i want it to put all the files from folder, "C:/Files/" so each files in that directory will be added to the listview, ? how can i do this? i mean what is the code?

Thanks hehaho;
User avatar
AnoPem
VIP - Donator
VIP - Donator
Posts: 441
Joined: Sat Jul 24, 2010 10:55 pm

You could do this
Code: Select all
        Dim path = "C:/Files/"

        Dim lpath = path.LastIndexOf("\")
        Dim fpath = path.Replace(lpath, "")
        For Each file As String In System.IO.Directory.GetFiles(path)
            Dim item As New ListViewItem(System.IO.Path.GetFileName(file))
            ListView1.Items.Add(item)
            item.SubItems.Add(fpath)
        Next
https://t.me/pump_upp
User avatar
CodenBoy
Top Poster
Top Poster
Posts: 103
Joined: Sun Jul 15, 2012 4:06 pm

Thanks AnoPem, this worked great,

Thanks bro :)
3 posts Page 1 of 1
Return to “Coding Help & Support”