-
May 23rd, 2015, 09:15 AM
#1
Thread Starter
Member
Deleting FILES in a folder from a listbox
Hello,
Here is what I'm trying to accomplish here. I have a textbox1 and it is for typing in a FILE name and press add, it adds it to a listbox. Now I want to press Delete From Playlist and when I press that button it deletes the file from the folder.
Currently the code I have works but I need to call all items from the listbox to delete.
So basically I need to the file location to stay the same but change MEDIA01234 to whatever items are in listbox. Items in listbox are alway changing there could be 1 - 100 items.
What do you think we need to do here?
Code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
My.Computer.FileSystem.DeleteFile("C:\Server Media\Playback1\Media01234")
My.Computer.FileSystem.DeleteFile("C:\Server Media\Playback2\Media01234")
End Sub
-
May 23rd, 2015, 09:25 AM
#2
Re: Deleting FILES in a folder from a listbox
You want to delete all of the files listed in the listbox, or all of the selected files in the listbox?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 23rd, 2015, 09:27 AM
#3
Thread Starter
Member
Re: Deleting FILES in a folder from a listbox
Right now I just want to delete all items that have been added to listbox. Currently I have a remove selected item if that needs to happen
-
May 23rd, 2015, 12:27 PM
#4
Re: Deleting FILES in a folder from a listbox
just loop though the listbox:
for each o as object in listbox1.items
delete(path & "\" & o.tostring)
next
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 23rd, 2015, 12:42 PM
#5
Thread Starter
Member
Re: Deleting FILES in a folder from a listbox
Alright. Im confused. How exactly do I get that bit of code to work
-
May 23rd, 2015, 01:02 PM
#6
Re: Deleting FILES in a folder from a listbox
what's confusing about that?
delete is pseudocode, but everything else is vb.
change path to "c:\somefolder\etc"
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 23rd, 2015, 01:35 PM
#7
Thread Starter
Member
Re: Deleting FILES in a folder from a listbox
So if my code is:
Code:
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
My.Computer.FileSystem.DeleteFile("C:\Server Media\WFVX Playback\Media01234)
End Sub
Change it to this:
Code:
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
My.Computer.FileSystem.DeleteFile("C:\Server Media\Playback" & o.tostring)
End Sub
Not really sure exactly how to implement what your saying into this code, I'm new at this. Do I need to add code somewhere else as well?
-
May 23rd, 2015, 02:22 PM
#8
Re: Deleting FILES in a folder from a listbox
Code:
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
for each o as object in listbox1.items
My.Computer.FileSystem.DeleteFile("C:\Server Media\WFVX Playback\" & o.tostring)
next
End Sub
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 23rd, 2015, 02:30 PM
#9
Thread Starter
Member
Re: Deleting FILES in a folder from a listbox
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|