Results 1 to 9 of 9

Thread: Deleting FILES in a folder from a listbox

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2015
    Posts
    42

    Exclamation 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

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    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?

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2015
    Posts
    42

    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

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    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

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2015
    Posts
    42

    Re: Deleting FILES in a folder from a listbox

    Alright. Im confused. How exactly do I get that bit of code to work

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    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"

  7. #7

    Thread Starter
    Member
    Join Date
    Apr 2015
    Posts
    42

    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?

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    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

  9. #9

    Thread Starter
    Member
    Join Date
    Apr 2015
    Posts
    42

    Re: Deleting FILES in a folder from a listbox

    that worked thanks

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
  •  



Click Here to Expand Forum to Full Width