Deltree




'Esempio d'utilizzo


Call VbDelTree("C:\DATA\MYDIR")

Restituisce TRUE se l'operazione ha avuto successo

Function VbDelTree(strDirectory As String) As Boolean

On Error GoTo HandleError

Dim strOriginalDir As String
Dim strFilename As String

If Len(Dir(VbFixPath(strDirectory), vbDirectory)) = 0 Then
Exit Function
End If

strOriginalDir = CurDir
ChDir strDirectory

strFilename = Dir("*.*")
Do Until strFilename = ""
Kill strFilename
strFilename = Dir
Loop

Do
strFilename = Dir("*.*", vbDirectory)

Do While strFilename = "." Or strFilename = ".."
strFilename = Dir
Loop

If strFilename = "" Then
Exit Do
Else
If Not VbDelTree(strFilename) Then
GoTo ExitHere
End If
End If
Loop

ChDir strOriginalDir

RmDir strDirectory
VbDelTree = True

ExitHere:
Exit Function
HandleError:
Select Case Err.Number
Case Else
MsgBox Err.Description, vbExclamation, _
"Error " & Err.Number & " in VbDelTree"
Resume ExitHere
End Select
End Function

Function VbFixPath(strPath As String) As String

strPath = Trim(strPath)
If Right(strPath, 1) <> "\" Then
VbFixPath = strPath & "\"
Else
VbFixPath = strPath
End If
End Function











( deltree.html )- by Paolo Puglisi - Modifica del 17/12/2023