CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Threaded View

  1. #1
    Join Date
    Dec 2008
    Posts
    7

    Use ListBox content to Delete files in directory and all subfolders

    VB.net 2008 express
    This is what I have so far, and it loads a list of files from a text file. Now I need to be able to delete them all from a certain drive and all sub folders in it. For instance I push the delete button and it goes through the entire list and deletes all the files in it from the designated drive and all it's sub folders.
    Any help is appreciated

    Code:
    Public Class Form1
        Inherits System.Windows.Forms.Form
    
    #Region " Windows Form Designer generated code "
    
        Public Sub New()
            MyBase.New()
    
            'This call is required by the Windows Form Designer.
            InitializeComponent()
    
            'Add any initialization after the InitializeComponent() call
    
        End Sub
    
        'Form overrides dispose to clean up the component list.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub
    
        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer
    
        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        Friend WithEvents ListBox2 As System.Windows.Forms.ListBox
        Friend WithEvents deletebutton As System.Windows.Forms.Button
        Friend WithEvents Button2 As System.Windows.Forms.Button
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Me.ListBox2 = New System.Windows.Forms.ListBox
            Me.Button2 = New System.Windows.Forms.Button
            Me.deletebutton = New System.Windows.Forms.Button
            Me.SuspendLayout()
            '
            'ListBox2
            '
            Me.ListBox2.Location = New System.Drawing.Point(12, 12)
            Me.ListBox2.Name = "ListBox2"
            Me.ListBox2.Size = New System.Drawing.Size(296, 186)
            Me.ListBox2.TabIndex = 4
            '
            'Button2
            '
            Me.Button2.Location = New System.Drawing.Point(12, 204)
            Me.Button2.Name = "Button2"
            Me.Button2.Size = New System.Drawing.Size(110, 24)
            Me.Button2.TabIndex = 5
            Me.Button2.Text = "Load C:\Delete.txt"
            '
            'deletebutton
            '
            Me.deletebutton.Location = New System.Drawing.Point(13, 246)
            Me.deletebutton.Name = "deletebutton"
            Me.deletebutton.Size = New System.Drawing.Size(109, 23)
            Me.deletebutton.TabIndex = 6
            Me.deletebutton.Text = "Delete Files"
            Me.deletebutton.UseVisualStyleBackColor = True
            '
            'Form1
            '
            Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
            Me.ClientSize = New System.Drawing.Size(320, 293)
            Me.Controls.Add(Me.deletebutton)
            Me.Controls.Add(Me.Button2)
            Me.Controls.Add(Me.ListBox2)
            Me.Name = "Form1"
            Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
            Me.Text = "Form1"
            Me.ResumeLayout(False)
    
        End Sub
    
    #End Region
        Dim w As IO.StreamWriter
        Dim r As IO.StreamReader
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            r = New IO.StreamReader("c:\delete.txt")
            While (r.Peek() > -1)
                ListBox2.Items.Add(r.ReadLine)
            End While
            r.Close()
        End Sub
    
        Private Sub deletebutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles deletebutton.Click
    
        End Sub
    End Class
    Last edited by MaxDes; May 11th, 2009 at 05:07 PM. Reason: more info

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

Featured