Deleting Files From A Listbox

Do you need something made? then ask 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
NoWayIn
VIP - Donator
VIP - Donator
Posts: 444
Joined: Sat Nov 21, 2009 11:16 pm

Deleting Files From A Listbox
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 )
User avatar
EwoudVL
New Member
New Member
Posts: 11
Joined: Fri Jan 29, 2010 8:07 am

Re: Deleting Files From A Listbox
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
NoWayIn
VIP - Donator
VIP - Donator
Posts: 444
Joined: Sat Nov 21, 2009 11:16 pm

Re: Deleting Files From A Listbox
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;
3 posts Page 1 of 1
Return to “Tutorial Requests”