Без FSO.
Можно ли как-то по простому, типа Kill c какой-нибудь константой vbDirectory?
Function DelTree(ByVal strDir As String) As Long
Dim xxx As Long
Dim intAttr As Integer
Dim strAllDirs As String
Dim strFile As String
DelTree = -1
On Error Resume Next
strDir = Trim$(strDir)
If Len(strDir) = 0 Then Exit Function
If Right$(strDir, 1) = "\" Then strDir = Left$(strDir, Len(strDir) - 1)
If InStr(strDir, "\") = 0 Then Exit Function
intAttr = GetAttr(strDir)
If (intAttr And vbDirectory) = 0 Then Exit Function
strFile = Dir$(strDir & "\*.*", vbSystem Or vbDirectory Or vbHidden)
Do While Len(strFile)
If strFile <> "." And strFile <> ".." Then
intAttr = GetAttr(strDir & "\" & strFile)
If (intAttr And vbDirectory) Then
strAllDirs = strAllDirs & strFile & Chr$(0)
Else
If intAttr <> vbNormal Then
SetAttr strDir & "\" & strFile, vbNormal
If Err Then DelTree = Err: Exit Function
End If
Kill strDir & "\" & strFile
If Err Then DelTree = Err: Exit Function
End If
End If
strFile = Dir$
Loop
Do While Len(strAllDirs)
xxx = InStr(strAllDirs, Chr$(0))
strFile = Left$(strAllDirs, xxx - 1)
strAllDirs = Mid$(strAllDirs, xxx + 1)
xxx = DelTree(strDir & "\" & strFile)
If xxx Then DelTree = xxx: Exit Function
Loop
RmDir strDir
If Err Then
DelTree = Err
Else
DelTree = 0
End If
End Function
Сейчас этот форум просматривают: AhrefsBot, SemrushBot и гости: 5