ident Posted May 29, 2008 Posted May 29, 2008 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, Quote
Administrators PlausiblyDamp Posted May 30, 2008 Administrators Posted May 30, 2008 To get the list of files you can just do dim files() as string = System.io.directory.getfiles("c:\", "*.jpg") to delete a file you can use the system.io.file.delete() method. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Nate Bross Posted May 30, 2008 Posted May 30, 2008 To display the results in a list box control you can do this. '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 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. Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
ident Posted June 3, 2008 Author Posted June 3, 2008 what is wrong with this??? 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, Quote
Borix Posted June 3, 2008 Posted June 3, 2008 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... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.