Page 1 of 1

Deleting Files From A Listbox

Posted: Sat Mar 13, 2010 9:46 am
by NoWayIn
So I was just wondering how you do this...

I'm going to have some buttons and for each button when they are click they will add an item to the Listbox1.
The item will wither be a Directory or File Name like
C:\Program.exe
or
Program.exe

I want to be able to delete that file when the form is closing.

so let's say I have 3 items in my listbox
Program.exe
Program2.exe
Program3.exe

When my program close it will delete all those 3 files ( not from the listbox but from the computer )

Re: Deleting Files From A Listbox

Posted: Sat Mar 13, 2010 10:41 am
by EwoudVL
You need 1 button, 1 listbox and 1 openfiledialog for it , then use this code:
Code: Select all
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        OpenFileDialog1.ShowDialog()
        ListBox1.Items.Add(OpenFileDialog1.FileName)

    End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Try


            For Each path As String In ListBox1.Items
                Kill(path)

            Next
        Catch ex As Exception

        End Try
    End Sub
End Class

Re: Deleting Files From A Listbox

Posted: Sat Mar 13, 2010 7:24 pm
by NoWayIn
I don't want to show openfiledialog

I want to delete those files from my computer automatically and I don't want to know that it's been deleted.

What I'm doing is extracting some files from my program and I want them to be deleted after I use the program

EDIT : Never-mind I found out how to do it now, it was simple and I didn't think of it idoit;