Titre: Lister des fichiers, répertoires...

Description:

Liste tous les fichiers OU tous les dossiers, ou tous les fichiers ET tous les dossiers , ou tous les fichiers avec une extension "*.xxx".

Le code:

Option Explicit
Dim LS$
Private Sub Command2_Click()
Dim MyPath, MyName
Lst.Clear
MyName = Dir(Dir1.Path & "\", vbDirectory) 'Extrait la première entrée.
Do While MyName <> "" 'Commence la boucle.
'Ignore le dossier courant et le dossier contenant le dossier courant.
If MyName <> "." And MyName <> ".." Then
'Utilise une comparaison au niveau du bit pour vérifier que MyName est un dossier.
If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
Lst.AddItem MyName, 0
End If
End If
MyName = Dir 'Extrait l'entrée suivante.
Loop
End Sub

Private Sub Command3_Click()
Dim MyPath, MyName
Lst.Clear
MyName = Dir(Dir1.Path & "\", vbDirectory) 'Extrait la première entrée.
Do While MyName <> "" 'Commence la boucle.
'Ignore le dossier courant et le dossier contenant le dossier courant.
If MyName <> "." And MyName <> ".." Then
Lst.AddItem MyName, 0
End If
MyName = Dir 'Extrait l'entrée suivante.
Loop
End Sub

Private Sub Command4_Click()
Dim MyPath, MyName
Lst.Clear
MyName = Dir(Dir1.Path & "\", vbDirectory) 'Extrait la première entrée.
Do While MyName <> "" 'Commence la boucle.
'Utilise une comparaison au niveau du bit pour vérifier que MyName est un dossier.
If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then GoTo Saut1:
Lst.AddItem MyName, 0
Saut1:
MyName = Dir 'Extrait l'entrée suivante.
Loop
End Sub


Private Sub Command5_Click()
Dim MyPath, MyName
Lst.Clear
MyName = Dir(Dir1.Path & "\", vbDirectory) 'Extrait la première entrée.
Do While MyName <> "" 'Commence la boucle.
'Utilise une comparaison au niveau du bit pour vérifier que MyName est un dossier.
If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then GoTo Saut1:
If Right(LCase(MyName), 4) = ".tex" Then 'Extension .TEX(Attention majuscule/minuscule)
Lst.AddItem MyName, 0
End If
Saut1:
MyName = Dir 'Extrait l'entrée suivante.
Loop
End Sub

Private Sub Form_Load()
LS = Chr(13) & Chr(10)
End Sub