/ Published in: Visual Basic
How to list files in directories and subdirectories ?
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
Option Explicit Sub ListeFichiersRepert() Dim Fso As Object Dim MonRepertoire As String, f As Object, x As Integer Dim f1 As Object, f2 As Object Set Fso = CreateObject("Scripting.FileSystemObject") MonRepertoire = "C:\Users\Moi\Documents\Dossier Excel" x = 1 For Each f In Fso.GetFolder(MonRepertoire).Files Cells(x, 1).Value = f.Name x = x + 1 Next f x = 1 For Each f1 In Fso.GetFolder(MonRepertoire).SubFolders Cells(x, 2).Value = f1.Name x = x + 1 For Each f2 In f1.Files Cells(x - 1, 3).Value = f2.Name x = x + 1 Next f2 x = x - 1 Next f1 End Sub