وعليكم السلام ورحمة الله وبركاته 🙂
تفضل يا سيدي ، دالة تحذف المجلد واللي فيه :
Function DelFolder(ByVal strDir As String) As Long
On Error Resume Next
' to delete the directory and its contents
Dim x As Long
Dim intAttr As Integer
Dim strAllDirs As String
Dim strFile As String
DelFolder = -1
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 DelFolder = Err: Exit Function
End If
Kill strDir & "\" & strFile
If Err Then DelFolder = Err: Exit Function
End If
End If
strFile = Dir$
Loop
Do While Len(strAllDirs)
x = InStr(strAllDirs, Chr$(0))
strFile = Left$(strAllDirs, x - 1)
strAllDirs = Mid$(strAllDirs, x + 1)
x = DelFolder(strDir & "\" & strFile)
If x Then DelFolder = x: Exit Function
Loop
RmDir strDir
If Err Then
DelFolder = Err
Else
DelFolder = 0
End If
End Function
جعفر