Re : Recherche dans dossier et affichage
Re
aleniox
[pour la partie listage des noms de fichiers]
Essayes ce code sur un userform sur lequel tu auras insérer une ListView
Puis affiche l'userform et sélectionne le répertoire de ton choix
Code VB:
Private Sub UserForm_Initialize()
'mixage d'un code rédigé par cytop
'et du code cité dans mon fil précédent
Dim fso As Object
Dim fldr As Object
Dim Files As Object
Dim oFile As Object
Dim li As ListItem
Dim objShell As Object, objFolder As Object
Dim SecuriteSlash As Integer
Dim Chemin As String
On Error GoTo ErrHandler
'Définit les entêtes de colonnes
With ListView1
With .ColumnHeaders
.Clear 'Supprime les anciens entêtes
'Ajout des colonnes
.Add , , "Nom", 200
.Add , , "Type", 85, lvwColumnLeft
.Add , , "Taille", 75, lvwColumnRight
End With
.View = lvwReport 'affichage en mode Rapport
.Gridlines = True 'affichage d'un quadrillage
.FullRowSelect = True 'Sélection des lignes complètes
End With
Set objShell = CreateObject("Shell.Application")
'recuperer nom repertoire cible
'de Frederic Sigonneau
Set objFolder = objShell.BrowseForFolder(&H0&, "Choisir un répertoire", &H1&)
On Error Resume Next
Chemin = objFolder.ParentFolder.ParseName(objFolder.Title).Path
If objFolder.Title = "" Then Chemin = ""
SecuriteSlash = InStr(objFolder.Title, ":")
If SecuriteSlash > 0 Then Chemin = Mid(objFolder.Title, SecuriteSlash - 1, 2) & ""
If Chemin = "" Then Exit Sub
Set fso = CreateObject("Scripting.FileSystemObject")
Set fldr = fso.GetFolder(Chemin)
Set Files = fldr.Files
For Each oFile In Files
Set li = ListView1.ListItems.Add(, , oFile.Name)
li.SubItems(1) = oFile.Type
li.SubItems(2) = Format$(oFile.Size, "0")
Next
EndProc:
On Error Resume Next
Set li = Nothing
Set oFile = Nothing
Set fldr = Nothing
Set fso = Nothing
Exit Sub
ErrHandler:
MsgBox "ERROR: " & Err.Description, vbExclamation, "Error"
Resume EndProc
End Sub