Effacer un répertoire
- Code : Tout sélectionner
Public Function DirectoryDelete(wPath,wnbForce As Integer) As Integer
'fonction non récursive sur les sous-répertoire
'wnbforce = supprime les fichiers présent dans le répertoire (mais pas les sous répertoire)
Dim File As String
Dim Path As String
Dim lstValue List As String
Dim i As Integer
On Error Goto ErreurHandle
'gere l'erreur de suppression
On Error 75 Goto ErreurHandle75
DirectoryDelete = True
If Trim(wPath) = "" Then
Exit Function
Elseif isValideDirectory(Trim(wPath)) = False Then
Exit Function
End If
If Right(Trim(wPath),1)<>"\" Then
Path = wPAth+"\"
Else
Path = wPath
End If
If wnbForce = True Then
i=0
File = Dir$(Path+"*.*",16)
While File <> ""
Select Case Trim(File)
Case ".",".."
'on fait rien
Case Else
i=i+1
lstValue(i) = Path+File
End Select
File = Dir$()
Wend
If i>0 Then
Forall value In lstValue
If Trim(Cstr(value)) <>"" Then
Kill value
End If
End Forall
Else
DirectoryDelete = False
Exit Function
End If
End If
Rmdir wPath
Exit Function
ErreurHandle75:
DirectoryDelete = False
Exit Function
ErreurHandle:
Msgbox "("+Cstr(Getthreadinfo (1))+" Call by "+Cstr(Getthreadinfo(10))+")"+Chr(10)+"Erreur " + Str(Err) + " : "+Chr(10) + Cstr(Error)+". "+Chr(10)+"Ligne N° "+Cstr(Erl),16," ERREUR !"
DirectoryDelete = False
Exit Function
End Function