vb.net "simple file scan"

ident

Newcomer
Joined
May 29, 2008
Messages
5
Firstly i am sorry if this is wrong section.

I have only just switched over from vb6 to vb.net(was beginner at vb6) & am trying to look for some source to learn from on file scan.

I wont to be able to scan say the c:\ for .jpg or something then have it listed in a list box,

Then be able to choose to either delete selected file or the entier group.

Thanks,
 
To get the list of files you can just do
Visual Basic:
dim files() as string = System.io.directory.getfiles("c:\", "*.jpg")

to delete a file you can use the system.io.file.delete(<file name>) method.
 
To display the results in a list box control you can do this.

Visual Basic:
'PD code:
dim files() as string = System.io.directory.getfiles("c:\", "*.jpg")

ListBox1.DataSource = files

Then you can drop this code behind your delete button

Visual Basic:
System.IO.File.Delete(ListBox1.SelectedItem)

Use caution when using this code as it will not put the deleted item into the Recycling Bin, once you delete it, it's gone.
 
what is wrong with this???

Code:
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        System.IO.File.Delete(ListBox1.SelectedItem)
        ListBox1.Items.RemoveAt(1)



    End Sub

I want to remove the list box entry,
 
Check to see if the index of the Items is out of the boundaries, i.e. there may be one and only one item in the collection (whose index is zero-based), and you are attempting to access "nothing" at index 1...
 
Back
Top