VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



The code acts like the DELTREE function in DOS. Pass it a Dir Path and it wipes that dir from the d

by Kevin Waltman (1 Submission)
Category: Files/File Controls/Input/Output
Compatability: Visual Basic 4.0 (32-bit)
Difficulty: Unknown Difficulty
Originally Published: Fri 16th June 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)

The code acts like the DELTREE function in DOS. Pass it a Dir Path and it wipes that dir from the drive, including ll files and sub-dirs in

Rate The code acts like the DELTREE function in DOS. Pass it a Dir Path and it wipes that dir from the d



'Code by Kevin Waltman
'[email protected]
'Dec 20,1999
'Free for distribution as long as the above comment lines are in place.
'This function loops upon itself to parse down through mutiple layers of _
 sub-dirs and files. The code is clean and requires no API or DLL's

On Error GoTo nogo 'Set up an error trap just in case
Dim filetemp As String
Dim etrap As Long
If Right(dirpath, 1) <> "\" Then dirpath = dirpath + "\" 'make sure passed _
                                                          path end in a '/'
filetemp = Dir(dirpath, vbDirectory)
Do While Trim(filetemp) <> "" 'parse sub-dirs
    If Trim(filetemp) <> "." And Trim(filetemp) <> ".." Then
        If (GetAttr(dirpath + filetemp) And vbDirectory) = vbDirectory Then
            etrap = Deltree(dirpath + filetemp)
            filetemp = Dir(dirpath, vbDirectory)
        Else
            filetemp = Dir(, vbDirectory)
        End If
    Else
        filetemp = Dir(, vbDirectory)
    End If
Loop
filetemp = Dir(dirpath + "*.*")
Do While Trim(filetemp) <> "" 'parse normal files
    SetAttr (dirpath + filetemp), vbNormal
    Kill (dirpath + filetemp)
    filetemp = Dir
Loop
filetemp = Dir(dirpath + "*.*", vbHidden)
Do While Trim(filetemp) <> "" 'parse hidden files
    SetAttr (dirpath + filetemp), vbNormal
    Kill (dirpath + filetemp)
    filetemp = Dir
Loop
If Right(dirpath, 1) = "\" Then dirpath = Mid(dirpath, 1, Len(dirpath) - 1)
SetAttr dirpath, vbNormal
RmDir (dirpath)
Deltree = 0
Exit Function
nogo: 'error trap sprung
Deltree = Err.Number
End Function

Download this snippet    Add to My Saved Code

The code acts like the DELTREE function in DOS. Pass it a Dir Path and it wipes that dir from the d Comments

No comments have been posted about The code acts like the DELTREE function in DOS. Pass it a Dir Path and it wipes that dir from the d. Why not be the first to post a comment about The code acts like the DELTREE function in DOS. Pass it a Dir Path and it wipes that dir from the d.

Post your comment

Subject:
Message:
0/1000 characters