Public Sub ListFilesInFolder(SourceFolderName As String, IncludeSubfolders As Boolean, TestRetour)
'exp: ListFilesInFolder "C:\FolderName\", True < avec sous dossiers) !!! récursivité (***)
Dim FSO, SourceFolder, SubFolder, FileItem, R As Long
Set FSO = CreateObject("Scripting.FileSystemObject")
Set SourceFolder = FSO.GetFolder(SourceFolderName)
If TestRetour = 0 Then
Cells.Clear
Columns.ColumnWidth = 10
Cells(3, 1) = "Fichier": Cells(3, 2) = "Créé": Cells(3, 3) = "Modifié": Cells(3, 4) = "Capacité": Cells(3, 5) = "Chemin"
End If
R = Range("A65536").End(xlUp).Row + 1
For Each FileItem In SourceFolder.Files
If ".mp3 .wave .mp4" Like "*" & Right(FileItem.Name, 4) & "*" Then ' pour ne pas lister les images des jacquettes
Cells(R, 1).Formula = FileItem.Name
Cells(R, 2).Formula = FileItem.DateCreated
Cells(R, 3).Formula = FileItem.DateLastModified
If FileItem.Size >= 1024 Then
Cells(R, 4).Formula = Int(FileItem.Size / 1024) & " Ko"
Else
Cells(R, 4).Formula = FileItem.Size & " Oct"
End If
ActiveSheet.Hyperlinks.Add Cells(R, 5), FileItem.Path ' FileItem.Name
'Cells(R, 5).Formula = SourceFolderName 'FileItem.Path
R = R + 1
End If
Next
If IncludeSubfolders Then
For Each SubFolder In SourceFolder.SubFolders
ListFilesInFolder SubFolder.Path, True, 1 '(***)
Next
End If
Columns.AutoFit
Set FileItem = Nothing
Set SourceFolder = Nothing
Set FSO = Nothing
End Sub