How do I delete folders using vb5???

How do I delete folders whit all the files in and how

do I search and delete a specific file and how do I delete every file whit (Just an exampel) BMP in the windows directory or any other directory? All using Vb 5 code???


I need urgent help!




Comments

  • : How do I delete folders whit all the files in and how

    : do I search and delete a specific file and how do I delete every file whit (Just an exampel) BMP in the windows directory or any other directory? All using Vb 5 code???


    : I need urgent help!


    You can delete a folder my using the command: Rmdir "c:yourpath"

    You can't remove a directory that has files in it though. You have to

    delete all the files first. You can do this with the kill statement.

    ie..Kill "c:yourpathfilename"

    You can also use wildcards with the kill statement to pick out certain

    files to delete in a folder. For example: Kill "c: emp*.bmp" would

    delete all .bmp files in the C: emp directory.

    As far as deleting files in directories and their subdirectories, I don't know.




  • This is the main core of a program I wrote to search all files in a specified directory and down. It is written in VB3, but should work in VB5. To make the stop button work correctly you must globalize a variable called StopIt.


    To delete a folder you have to delete EVERY file and folder under it. This program can easily do this with a few modifications. Since it already searches out every file and folder, it is a simple matter to get every entry that ends with bmp or txt, etc. and delete them.


    Just save this to a file with the extension frm and you should be able to load and run.


    VERSION 2.00

    Begin Form CreateNw

    BackColor = &H00C0C0C0&

    BorderStyle = 3 'Fixed Double

    Caption = "Figure it out!"

    ClientHeight = 6150

    ClientLeft = 2385

    ClientTop = 1500

    ClientWidth = 6990

    Height = 6555

    Left = 2325

    LinkTopic = "Form1"

    MaxButton = 0 'False

    ScaleHeight = 6150

    ScaleWidth = 6990

    Top = 1155

    Width = 7110

    Begin DriveListBox Drive1

    Height = 315

    Left = 4920

    TabIndex = 5

    Top = 3480

    Width = 1935

    End

    Begin CommandButton Command2

    Cancel = -1 'True

    Caption = "Sto&p"

    Height = 495

    Left = 5280

    TabIndex = 4

    Top = 4800

    Width = 1215

    End

    Begin ListBox List1

    Height = 5880

    Left = 120

    MultiSelect = 1 'Simple

    TabIndex = 0

    Top = 120

    Width = 4575

    End

    Begin FileListBox File1

    Height = 420

    Hidden = -1 'True

    Left = 120

    System = -1 'True

    TabIndex = 3

    Top = 120

    Width = 1215

    End

    Begin CommandButton Command1

    Caption = "&Search"

    Default = -1 'True

    Height = 495

    Left = 5280

    TabIndex = 2

    Top = 4080

    Width = 1215

    End

    Begin DirListBox Dir1

    ForeColor = &H00000000&

    Height = 3180

    Left = 4920

    TabIndex = 1

    Top = 120

    Width = 1935

    End

    Begin Label Label1

    Alignment = 2 'Center

    BackColor = &H00C0C0C0&

    Caption = "????"

    Height = 255

    Left = 5400

    TabIndex = 6

    Top = 5520

    Width = 975

    End

    End


    Sub Command1_Click ()

    Label1.Caption = "????"

    List1.Clear

    DoEvents

    SearchCur

    Label1.Caption = List1.ListCount

    End Sub


    Sub Command2_Click ()

    StopIt = True

    End Sub


    Sub Dir1_Change ()

    File1.Path = Dir1.Path

    End Sub


    Sub Drive1_Change ()

    Dir1.Path = Drive1.Drive

    End Sub


    Sub Search ()

    If StopIt Then

    StopIt = False

    Exit Sub

    End If

    For I = 0 To Dir1.ListCount - 1

    Dir1.Path = Dir1.List(I)

    List1.AddItem Dir1.Path

    For X = 0 To File1.ListCount - 1

    If Right$(Dir1.Path, 1) <> "" Then

    List1.AddItem Dir1.Path & "" & File1.List(X)

    Else

    List1.AddItem Dir1.Path & File1.List(X)

    End If

    Next X

    DoEvents

    If StopIt Then

    StopIt = False

    Exit Sub

    End If

    If Dir1.ListCount > 0 Then Search

    Dir1.Path = Dir1.List(-2)

    Next I

    End Sub


    Sub SearchCur ()

    List1.AddItem Dir1.Path

    For X = 0 To File1.ListCount - 1

    If Right$(Dir1.Path, 1) <> "" Then

    List1.AddItem Dir1.Path & "" & File1.List(X)

    Else

    List1.AddItem Dir1.Path & File1.List(X)

    End If

    Next X

    Search

    End Sub



    Hope this helps!


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories