Effacer un répertoire

Effacer un répertoire

Messagepar Michael DELIQUE » 17 Oct 2007 à 12:13

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
Cordialement

Michael (SMS-Phobique)
----------------------------
"La théorie, c'est quand on sait tout et que rien ne fonctionne. La pratique, c'est quand tout fonctionne et que personne ne sait pourquoi."
Albert EINSTEIN
Avatar de l’utilisateur
Michael DELIQUE
Administrateur
Administrateur
 
Message(s) : 12183
Inscrit(e) le : 16 Déc 2004 à 10:36
Localisation : Paris/Cergy

Messagepar Wildcat » 26 Juil 2010 à 14:34

Utilise la fonction isValideDirectory du tip Tester l'existence d'un répertoire
Avatar de l’utilisateur
Wildcat
Premier posts
Premier posts
 
Message(s) : 19
Inscrit(e) le : 06 Jan 2010 à 11:11
Localisation : Montpellier


Retour vers Gestion de fichiers