Page 1 of 1

All files in a folder to ListView?

Posted: Thu Aug 09, 2012 9:06 pm
by 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;

Re: All files in a folder to ListView?

Posted: Thu Aug 09, 2012 9:36 pm
by AnoPem
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

Re: All files in a folder to ListView?

Posted: Thu Aug 09, 2012 10:09 pm
by CodenBoy
Thanks AnoPem, this worked great,

Thanks bro :)