Results 1 to 3 of 3

Thread: easy easy question

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2000
    Posts
    49
    is there a way in visual basic to delete a folder that contains files our other folders, like a deltree in dos.
    I've tried "rmdir (path)" but there is a error if the folder contains file.
    thanxs

  2. #2
    Guest
    Just use Deltree.

    Code:
    Shell "DELTREE /Y (path)", vbHide
    Becareful, this could delete important files. It is very dangerous!

  3. #3
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    Code:
    'You Need Microsoft Scripting Control for this.
    'Not verified
    Dim fOps As Object
    
    Private Function DelTree(dirPath As String, Optional delReadOnly As Boolean) As Boolean
        Set fOps = CreateObject("Scripting.FileSystemObject")
    
        If fOps.FolderExists(dirPath) = True Then
            If delReadOnly <> True Then
                fOps.DeleteFolder dirPath
                Else
                fOps.DeleteFolder dirPath, delReadOnly
            End If
            DelTree = True
            Else
            DelTree = False
        End If
    End Function
    This uses the Microsoft Scripting Control to create the object, but it's a pretty decent solution (I like the FileSystemObject :)

    The Function is called thusly: DidDelete = delTree(PATH,[True/False])

    If True is set, it will delete read only folders, if false is set, it will not. Path is the directory you wish to delete. The function returns either a true or a false indicating it's level of success.
    -Excalibur

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